Skip to content

Commit 692fb3f

Browse files
authored
refactor: replace stoplight/yaml with yaml (eemeli) (#206)
* refactor: migrate YAML parser from stoplight/yaml to yaml (eemeli) Problem: stoplight/yaml has unfixed bugs in block scalar chomping (|+ loses trailing blank lines, explicit indent indicators like |2 produce a spurious leading newline). Furthermore the library is effectivelly unmaintained. Solution: Replace stoplight/yaml with the actively maintained yaml (eemeli) package. Comment preservation is re-implemented using a path-based extract/inject strategy. * docs: remove stoplight studio section from readme * test: update expected output for quote normalization * test: update expected output for behaviors broken in stoplight/yaml - yaml-default-newline: block scalar chomping (|+ keep, |- strip, | clip) now behaves correctly. |+ doesn't lose trailing blank lines, and spurious leading newlines are not created. - yaml-no-sort-keep-comments: a valueCommentBefore (key: # comment above a block node) is re-emitted on its own line below the key rather than inline. This is a known rendering difference of the new path-based inject approach; the YAML is semantically equivalent.
1 parent 904d78c commit 692fb3f

78 files changed

Lines changed: 1330 additions & 1331 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

Lines changed: 28 additions & 96 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"release": "npx np --branch main"
3838
},
3939
"dependencies": {
40-
"@stoplight/yaml": "^4.3.0",
40+
"yaml": "^2.8.3",
4141
"api-ref-bundler": "^0.5.0",
4242
"case-anything": "2.1.10",
4343
"jsonpathly": "^3.0.0",
@@ -76,4 +76,4 @@
7676
"directories": {
7777
"test": "test"
7878
}
79-
}
79+
}

readme.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,18 +1699,6 @@ For handling AsyncAPI documents, we have created a separate
16991699
package [asyncapi-format](https://github.com/thim81/asyncapi-format) to allow customisation specific for AsyncAPI
17001700
use-cases.
17011701

1702-
## Stoplight Studio
1703-
1704-
We have adopted the YAML parsing style from [Stoplight Studio](https://stoplight.io/studio/), by leveraging
1705-
the [@stoplight/yaml](https://www.npmjs.com/package/@stoplight/yaml) package for handling the parsing of OpenAPI YAML
1706-
files.
1707-
1708-
By using the Stoplight YAML parsing, the results will be slightly different from when using a normal YAML parsing
1709-
library, like [js-to-yaml](https://www.npmjs.com/package/js-yaml). We appreciate the Stoplight Studio tool, since it is
1710-
an excellent GUI for working with OpenAPI documents for non-OpenAPI experts who will be contributing changes. By
1711-
adopting the Stoplight Studio YAML parsing, the potential risk of merge conflicts will be lowered, which is the main
1712-
reason why we opted for using the @stoplight/yaml package.
1713-
17141702
## Credits
17151703

17161704
This package is inspired by
@@ -1727,4 +1715,4 @@ The casing options available in `openapi-format` are powered by the excellent [c
17271715
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.png" alt="JetBrains logo." width="200px">
17281716
</a>
17291717

1730-
Special thanks to [JetBrains](https://www.jetbrains.com/) for their continuous sponsorship of this project over the last 3 years, and for their support to open-source software (OSS) initiatives.
1718+
Special thanks to [JetBrains](https://www.jetbrains.com/) for their continuous sponsorship of this project over the last 3 years, and for their support to open-source software (OSS) initiatives.

test/_split/snap.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ info:
44
version: 1.0.0
55
description: A compact version of the Train Travel API
66
paths:
7-
'/stations/{station_id}':
8-
$ref: 'paths/stations_{station_id}.yaml'
7+
/stations/{station_id}:
8+
$ref: paths/stations_{station_id}.yaml
99
components:
1010
schemas:
1111
Station:
12-
$ref: "components/schemas/Station.yaml"
12+
$ref: components/schemas/Station.yaml
1313
parameters:
1414
StationId:
15-
$ref: "components/parameters/StationId.yaml"
15+
$ref: components/parameters/StationId.yaml

test/_split/snap_station.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ get:
22
summary: Get station information
33
operationId: getStation
44
parameters:
5-
- $ref: "../components/parameters/StationId.yaml"
5+
- $ref: ../components/parameters/StationId.yaml
66
responses:
77
'200':
88
description: Successful operation
99
content:
1010
application/json:
1111
schema:
12-
$ref: "../components/schemas/Station.yaml"
12+
$ref: ../components/schemas/Station.yaml
1313
'404':
1414
description: Station not found

test/json-custom-yaml/output.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ info:
1111
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
1212
version: 1.0.6-SNAPSHOT
1313
title: Swagger Petstore - OpenAPI 3.0
14-
termsOfService: 'http://swagger.io/terms/'
14+
termsOfService: http://swagger.io/terms/
1515
contact:
1616
email: apiteam@swagger.io
1717
license:
1818
name: Apache 2.0
19-
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
19+
url: http://www.apache.org/licenses/LICENSE-2.0.html
2020
servers:
2121
- url: /v3
2222
paths:
@@ -52,8 +52,8 @@ paths:
5252
description: Invalid input
5353
security:
5454
- petstore_auth:
55-
- 'write:pets'
56-
- 'read:pets'
55+
- write:pets
56+
- read:pets
5757
tags:
5858
- pet
5959
put:
@@ -91,8 +91,8 @@ paths:
9191
description: Validation exception
9292
security:
9393
- petstore_auth:
94-
- 'write:pets'
95-
- 'read:pets'
94+
- write:pets
95+
- read:pets
9696
tags:
9797
- pet
9898
/pet/findByStatus:
@@ -131,8 +131,8 @@ paths:
131131
description: Multiple status values can be provided with comma separated strings
132132
security:
133133
- petstore_auth:
134-
- 'write:pets'
135-
- 'read:pets'
134+
- write:pets
135+
- read:pets
136136
tags:
137137
- pet
138138
components:
@@ -337,10 +337,10 @@ components:
337337
type: oauth2
338338
flows:
339339
implicit:
340-
authorizationUrl: 'https://petstore.swagger.io/oauth/authorize'
340+
authorizationUrl: https://petstore.swagger.io/oauth/authorize
341341
scopes:
342-
'write:pets': modify pets in your account
343-
'read:pets': read your pets
342+
write:pets: modify pets in your account
343+
read:pets: read your pets
344344
api_key:
345345
type: apiKey
346346
name: api_key
@@ -350,7 +350,7 @@ tags:
350350
description: Everything about your Pets
351351
externalDocs:
352352
description: Find out more
353-
url: 'http://swagger.io'
353+
url: http://swagger.io
354354
externalDocs:
355355
description: Find out more about Swagger
356-
url: 'http://swagger.io'
356+
url: http://swagger.io

0 commit comments

Comments
 (0)