Skip to content

Commit

Permalink
REST: Replace abandoned @apidevtools/swagger-cli
Browse files Browse the repository at this point in the history
`@redocly/cli` is actively maintained, supports OpenAPI definition v3.1, and has better validation of OpenAPI schemas.

Due to the way we dereference the schema with `redocly bundle` the resulting openapi.json file is approximately 7x bigger than before.

Requires removing the `nullable` field from `data_type` in `PropertyValuePair` as it is now deprecated and the `openapi-response-validator` package doesn't support OpenAPI specification v3.1. This functionality should be reintroduced (via `"type": [ "string", "null" ]`) when all our tooling supports OpenAPI specification v3.1.

Change-Id: Ib64971467a77eeadec82da85c204cc722a3c5121
  • Loading branch information
outdooracorn committed Nov 6, 2024
1 parent a58361c commit efc40b0
Show file tree
Hide file tree
Showing 11 changed files with 44,632 additions and 6,338 deletions.
3 changes: 2 additions & 1 deletion repo/rest-api/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"node_modules/",
"vendor",
"dist/",
"docs/"
"docs/",
".redocly.lint-ignore.yaml"
],
"rules": {
"max-len": [ "warn", { "code": 130 } ],
Expand Down
6 changes: 6 additions & 0 deletions repo/rest-api/.redocly.lint-ignore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.
# See https://redocly.com/docs/cli/ for more information.
specs/resources/index.json:
operation-4xx-response:
- '#/~1openapi.json/get/responses'
- '#/~1property-data-types/get/responses'
28 changes: 12 additions & 16 deletions repo/rest-api/docs/loaders/openapi-loader.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
const SwaggerParser = require( '@apidevtools/swagger-parser' );
const { bundle, loadConfig } = require( '@redocly/openapi-core' );
const path = require( 'path' );

module.exports = function ( _ ) {
const done = this.async();

this.addContextDependency( path.dirname( this.resourcePath ) );

SwaggerParser
.dereference(
this.resourcePath,
{
resolve: {
http: false
}
}
)
.then( ( spec ) => {
const baseUrl = process.env.API_URL || 'https://wikibase.example/w/rest.php';
loadConfig( { configPath: 'redocly.yaml' } )
.then( ( config ) => {
bundle( { ref: this.resourcePath, config, dereference: true } )
.then( ( result ) => {
const baseUrl = process.env.API_URL || 'https://wikibase.example/w/rest.php';

done( null, JSON.stringify( {
...spec,
servers: [ { url: baseUrl + '/wikibase/v1' } ]
} ) )
done( null, JSON.stringify( {
...result.bundle.parsed,
servers: [ { url: baseUrl + '/wikibase/v1' } ]
} ) );
} )
.catch( ( { message } ) => done( message ) );
} )
.catch( ( { message } ) => done( message ) );
};
Loading

0 comments on commit efc40b0

Please sign in to comment.