- Fixes generating example JSON bodies from Swagger Schema when the schema
contains a reference to a JSON path which prefixes the current path, for
example when handling a path such as
$ref: '#/definitions/User'
from a path which prefixes it such as$ref: '#/definitions/UserList'
.
additionalProperties
found within 'Schema Object' will now be translated into the parse result's data structure section.
- The HOST URI metadata produced from
schemes
,host
andbasePath
will now default tohttps
whenschemes
is not defined. Previously a partial URI without a scheme was returned.
Adds compatibility for @apielements/core 0.2.0.
- Improvements to generation of JSON message bodies to add more cases where
example
property of a Schema Object will be respected.
#515
- Performance improvements to OpenAPI 2 validation, this will only apply to validation only. Full OpenAPI 2 parsing is not altered.
-
Returns a validation error while trying to parse a YAML or JSON object which does not contain the
swagger
key, in prior versions the parser may have crashed under some inputs. -
Improved clarity of validation error messages.
-
Fixes a case where the source map information may be missing for one type of validation errors.
The package has been updated for compatibility with @apielements/core
.
- This release includes performance improvements to parsing documents which
contain the same schema re-used via a reference (
$ref
) many times in request parameters and response bodies under anallOf
key.
-
The parser will now produce a data structure for Schema Object's which do not contain a
type
. -
Added the
fixedType
attribute to array data structures which describe arrays with fixed types in the items. For example, the following schema which describes an array where the values MUST be of type string:type: array items: type: string
Previously we generated a data structure for an array which didn't fix the values of the array to be a string type. Instead provided an example that the value of the array MAY be a string.
-
Support required keys in a Schema Object which are not found in the properties list.
The package has been renamed to @apielements/openapi2-parser
.
-
Compatibility with Fury 3.0.0 Beta 14.
-
The parser can now be configured to disable generation of example message bodies and message body schemas by providing an adapter option
generateMessageBody
orgenerateMessageBodySchema
asfalse
during parse.
-
Adds support for
info.termsOfService
. For example the following document:swagger: '2.0' info: termsOfService: http://example.com/terms/
will add the link to the terms of service
http://example.com/terms/
-
Adds support for
info.contact
. For example the following document:swagger: '2.0' info: url: http://www.example.com/support email: [email protected]
will add a link to the contact URL and a second link to the contact email
- This release includes performance improvements to parsing documents which
contain the same schema re-used via a reference (
$ref
) many times in request parameters and response bodies.
- Sets an explicit
$schema
property on JSON Schema generated from a Swagger document inconvertSchema
. Sets a JSON Schema Draft V4 as the value of the$schema
property, making generated schema implement a JSON Schema Draft V4.
- Compatibility with Fury 3.0.0 Beta 13.
-
Prevents a 'Path Item Object' from being included in a Resource Group created by an 'Operation Object' in a previously defined 'Path Item Object'.
-
Optional parameters will now include an optional typeAttribute in the parse result. This will fix conversion to API Blueprint with fury-cli where optional parameters have shown up as required in the generated API Blueprint.
-
Allows generating of JSON bodies for schemas which make use of
allOf
and include circular references. Under some circumstances this would previously fail, and a warning may have been emitted "Unable to generate application/json example message body out of JSON Schema"
- Fixes a problem while parsing a document which contains a Swagger Schema for
a string which contains both a
minLength
and apattern
property which are incompatible. For example, the following pattern:^[A-z]*$
which is making use of*
which means that it allows strings that are zero length or more. If there is a propertyminLength
which is incompatible with the pattern such as ifminLength
is set to 1. Previously this would cause the parser to get into an infinite loop.
- Support for NodeJS 6 has been removed, upgrading to NodeJS 8 or newer is recommended.
-
JSON value generation will now support schemas which contain an array of objects. For example, the following schema:
type: array items: type: object properties: name: type: string example: doe
Will now emit a JSON value of
[{ "name": "doe" }]
, whereas before it would emit an empty array[]
. -
While parsing an 'Example Object' (found in a 'Schema Object') which contains an object with a property
length
anywhere in the example tree. The example object will be interpreted as an array of the given length. If the value oflength
property of an 'Example Object' is a large number, then the parser may utilise a lot of memory while producing a result and subsequently may cause out of memory failures.For example:
definitions: User: type: object example: length: 50000
- Fixes a potential parser crash while handling an example value for a 'Schema Object' which contains an invalid reference.
- Compatibility with Fury 3.0.0 Beta 10.
-
Support JSON Body generation when a schema contains an unknown "format". Previously this would cause a warning:
Unable to generate application/json example message body out of JSON Schema
-
Supports data structure generation for references for a value inside another definition. For example a reference to
#/definitions/User/properties/name
. -
Removes duplicate description values placed on members for data structure properties.
- Compatibility with Fury 3.0.0 Beta 9.
- Removed uses of
process.nextTick
which could cause any exceptions raised by the Fury adapter to be uncaught exceptions in Node JS. apiaryio/fury-adapter-swagger#169
- Fix cases where example values in schema definitions are not used in request or response bodies.
-
Fixes a case where having
null
as an enum value or havingx-nullable: true
on a schema withenum
will cause an obscure error:Cannot read property '$ref' of null
- Swagger Parser now requires Fury 3.0.0 Beta 8.
-
Adds support for generating JSON bodies for schemas where the root is an array. For example, given following array schema:
type: array items: type: string example: Doe
The parser will now generate a JSON body of
["Doe"]
whereas in previous versions would've resulted in an empty array. -
Fixes parsing Swagger documents that contain properties called
$ref
. Previously the parser would attempt to dereference the property as would generically try to dereference any key in an object called$ref
, as per the JSON Schema specification, references are only permitted when a schema type is expected.For example, the following is a schema which is trying to describe an object with a property called
$ref
, previously the parser would attempt to dereference$ref
and crash in the process.type: object properties: $ref: type: string example: '#/definitions/User' required: ['$ref']
There is a still an open known issue #235 that uses of
$ref
in a Swagger 2 document where the value a string will cause the parser to attempt to dereference it incorrectly when the$ref
property is found on an object that does not support$ref
as per the Swagger 2 and JSON Schema specifications.
-
While generating a data structure from a Swagger Schema, we will now attempt to infer when the schema should be an object but the user has forgotten to put
type: object
by looking for the presence ofproperties
in the schema. -
Adds support for object inheritance and mixins via
allOf
referencing in data structure generation.For example, the following will create an object which inherits from
User
:allOf: - $ref: '#/definitions/User' - properties: id: type: string
Secondly, when you reference multiple objects using
allOf
they will be treated as mixins:allOf: - $ref: '#/definitions/BaseUser' - $ref: '#/definitions/UserMixin'
-
Fixes using
x-nullable
in a schema which previously caused the schema not to be converted to a data structure. For example, the following schema wouldn't result in a data structure:type: string x-nullable: true
-
Fixes some cases where rendering a JSON example from a Swagger Schema using example values which contain references would fail.
- Fixes a regression introduced in 0.22.3 which caused a reference (
$ref
) from a definition to another definitions example value to fail.
- Example values in nested Schema Object will now be used for JSON body generation.
- Fixes a regression introduced in 0.22.0 where using
$ref
directly inside a Swagger Schema found within thedefinitions
section would cause a parsing failure.
- Fixes a regression introduced in 0.22.0 where the parse result may contain
invalid references inside a JSON Schema for example values if they used
references. This regression also caused
$ref
to be incorrectly present in Data Structure sample values.
- Adds a dataStructures section to the parse result containing every data structure found within the definitions section of a Swagger document. We now use referencing between data structures found within a request or response data structure which generally makes parse results smaller instead of duplicating the data structure contents.
- Adds support for primitive request bodies.
- No longer expand all option values (properties, array values) etc in the case that a schema has a circular reference.
- Line and column numbers are now exposed in the parse result in source maps for annotation elements.
-
Default and example values for headers are now validated to match the header type. For example, placing a string as a value for a number type header will now emit a warning.
-
Header values will now contain source map information in the parse result.
-
Fix support for type
file
in multipart-form body generation.
-
The API Version is now exposed in the parse result. The API category now contains a version attribute including the API version.
-
Circular references are now supported in schemas and JSON and JSON Schemas will now be present in parse results when you use circular references.
- Example values in a Schema Object will now be placed into the dataStructure as a value instead of inside samples in cases where there isn't already a value.
-
Return an error in the parse result when the source API Description Document is not an object. Previously an error was thrown.
-
When a request or response body has a schema of
format: binary
then we no longer generate a JSON Schema in the parse result. A JSON Schema for binary types doesn't make sense as you cannot place binary data in JSON. -
Example values found in schemas are now translated into examples in generated JSON Schema exposed in parse results.
-
Data Structure sample values will now include schema example values.
-
Request and Response body examples will now respect the example values of a schema.
-
When a schema uses
allOf
and doesn't provide a type hint at the schema root, theallOf
types are matched for object schemas. This allows the following schema to work where beforetype: object
was required at the schema root at the same level asallOf
:allOf: - type: object properties: username: type: string - type: object properties: name: type: string
- When using
enum
in conjunction withx-nullable
in a schema, this will now result in thenull
value being present in schema if it isn't already.
- Enumeration behaviour is now the same as API Elements 1.0 such that the values that are fixed will now have a fixed type attribute.
- Swagger
security-scheme
vendored extensions are now present in the parse result.
-
Supports detecting Swagger documents which are JSON formatted with spaces before the
:
. For example, the following document would not be matched to this adapter:{ "swagger" : "2.0" }
. -
When a parameter has no valid enumerations defined in an
enum
, we will now discard the enumeration in the parse result. Previously the parser would create an empty enumeration element from completely invalid enumerations in a Swagger document which can cause issues further down in subsequent tooling and Minim serialisation.
- Swagger Schemas are now recursively translated from Swagger schema into JSON
Schema draft 4 in the resultant messageSchema of a parse result. This fixes
bugs where components such as
x-nullable
,readOnly
,externalDocs
etc are not handled when found inside another schema as a sub-schema.
- Fixes an issue where auth scheme elements are re-used multiple times in a parse result which can cause exceptions when the parse result is frozen. This is in the case where you have multiple consumes so multiple request/response pairs are created for the action.
- Allow
date
anddate-time
format support.
- Support for Node 4 was removed. Node 6 is the minimum supported version of Node.
- Adds support for the
x-nullable
schema extension. This allows addingnull
as a type to a schema. This is an OpenAPI 3 feature ported to Swagger 2 as a vendored extension.
#112
- Optional object properties are now always present in generated JSON examples.
- Allow parsing Swagger parameters of array type which do not have samples and
offer
items
which does not include a type. - Coerce a resource
x-summary
value to a string if it is not already a string. When a user enters an incorrect type such as boolean, number or array. The title would become an incorrect type and can cause subsequent tooling to fail.
- Samples and Defaults of enum schema and parameters are now wrapped in enum element.
- File type parameters are now included instead of being ignored.
- Data Structure generation was not including required typeAttribute for required object properties.
- Sample values are now generated for data structures of object and array types.
- Request/Response pairs are now generated from explicit examples, or the first JSON produces content-type.
- Generated multipart form-data example requests were missing the end of the multi-part.
example
properties in Schema Object are not respected in data structure generation.
-
Prevent throwing or attaching additional warning while handling a source YAML document that produces an error while using the
generateSourceMap
flag.There was a race condition where the
done
callback can be called twice as we would call the callback with an error andfury
would catch a raised error and then return that error. This would also cause a state when parsing an invalid YAML document would produce an error AND a warning in the returned parse result.
- Request example bodies are now generated for formData parameters while using
the
multipart/form-data
consumes content type.
- Request and response pairs are now created for all combinations of produces, and consumes content types. This includes multiple JSON content types which we're previously discarded and non-JSON content types.
multipart/form-data
consumes type is no longer replaced byapplication/x-www-form-urlencoded
when formData parameters are provided. #96
- Added support for
externalDocs
. - Parser will now give warning about unsupported collection formats in parameters.
- Parameter default, example and enumerations values are now validated against the parameter type. Invalid values will emit warnings and be discarded, this resolves further problems when handling the invalid values.
- Data Structure generation will now support integer JSON Schema type.
- HOST metadata was incorrectly included in an attribute called
meta
. The attribute was renamed tometadata
in API Elements 1.0. - Fixes an issue where auth scheme elements are re-used multiple times in a parse result which can cause exceptions when the parse result is frozen.
- Handle array parameters which contain enumerations.
- Compatibility with Minim 0.19 and Fury 3.0.0-beta.4.
- Support
allOf
when generating data structures for objects
- Updated enum to match the new format
- Add warning when x-example is not of error type when defined as array
- Support
allOf
in object JSON Schemas when producing object data structure elements.
- Updates to fury 3.0.0-beta.3 which supports Refract 1.0 serialisation rules.
- Updates to fury 3.0.0-beta.2.
-
Adds support for
csv
andmulti
parameter collectionFormat for query parameters. -
Parameters which define both an example (
x-example
) anditems
schema will now use thex-example
value as the example. -
URI Template variables are now correctly escaped.
- Data Structure generation from JSON Schema handles array items which contain empty values.
- Data Structure elements are now generated from JSON Schema found in examples.
- Updated yaml-js dependency to 0.1.5. This resolves problems with determining source maps for Swagger documents that include multi-byte unicode characters such as emoji.
- Update fury to 3.0.0-beta.0
- Update minim to 0.15.0
- Update minim-parse-result to 0.4.0
- Upgraded babel-runtime dependency to v6
- Drop support for node 0.12 and 0.10
- Handle inheritance for Path level Parameters
-
Improve handling of default in parameters.
-
Prevent a crash on invalid media types, such as
application/json; invalid-component
and produce warnings for invalid media types.
- Fixes crashes on bad media types.
- Circular references in examples will now give a warning about not being supported yet.
-
Generates JSON examples for JSON subtypes such as
application/hal+json
. -
Fixes a crash during sourcemap construction for some specific documents
- Prevents constructing large arrays and strings when generating a request or
response body from a JSON Schema where there is a large
minItems
,maxItems
,minLength
ormaxLength
.
- Prevents dereferencing external assets such as local files.
-
Improves error reporting in some cases when references are involved.
-
Improves error reporting when the YAML document contains YAML syntax errors to include source maps and the YAML error.
- Added support to exclude extensions from operations
- Upgraded lodash dependency from 3.x.x to 4.x.x
- Added support for adding example values to parameters using
x-example
- Added support for parameter property called x-example, which allows to specify example values also for non-body parameters.
- The adapter is more asynchronous and thus, gives other events in the event loop the ability to run while we're parsing the Swagger document.
- Added authentication support.
- Swagger vendor extensions are now exposes as API Element extensions.
- Response and Request bodies are generated from Schema whenever applicable.
- Accept and Content-type headers are generated based on produces and consumes keys whenever applicable.
- Sample values for non-body parameters are generated whenever applicable.
- Header parameters are appended to request/response header collection.
- Added
formData
support and appropirate request body generation.
- Fixed metadata not being an array of Member Elements.
- Added source maps to resource.href, httpRequest.method, httpResponse.statusCode.
- Removed several unneeded source maps.
- Circular schema references will now give a warning about not being supported yet.
- Added fragment to uncaught error.
- Fixed bug with parameters sourcemaps when they are mixture of body and query parameters.
- All exceptions thrown when converting swagger to refract will now be caught and returned as a proper error in parse result
- Add an example for testing the module in the browser via TonicDev.
- Swagger's
operationId
is now correctly interpreted as transition element'sid
instead ofrelation
.
- Swagger documents that do not validate against the JSON Schema for Swagger will no longer be translated into Refract and instead expose errors for the validation failures.
- Bad JSON references (using
$ref
) are now returned as parse result annotations that include source maps which point to the$ref
line, making debugging easier.
-
Fix handling of resource
href
, which could get overwritten while processing transitions and result in missing parameters in the URI template. -
Code refactoring
- Parsing is now handled by a class to more easily share state between various methods. This lays the framework for more refactoring and code cleanup.
- The parser shared state tracks the path of the component currently being parsed, which makes it easier to split pieces of the parser into separate methods.
- YAML AST lookup paths are now arrays of strings rather than strings of period-separated components, which made escaping very difficult.
- Rather than guessing the YAML type, the AST lookup now checks and handles it accordingly. Paths like
'foo.bar.0.baz'
would fail previously and now work (but are passed as['foo', 'bar', '0', 'baz']
). - Underscore is now replaced with Lodash for consistency with other modules.
- Invalid YAML now returns error
- Add source maps for YAML parse error annotations, which were previously missing.
- Add support for
formData
parameters, which get converted into request data structures. - Add source maps for
messageBodySchema
assets.
- Do not encode JSON strings twice
- Support
x-summary
andx-description
in Path Item Objects
- Generate Swagger schema and spec validation annotations.
- Implement support for link relations in parser annotations.
- Encode dashes (
-
) in URI template parameters.
- Implement support for parser annotations.
- Implement support for source maps.
- Fixes bug where URI templates appended empty query section.
- Fixes additional slashes in URLs when basePath ends with
/
.
- Handle Swagger extensions (
x-*
fields). - Support tags as resource groups when possible.
- Support hostname and basepath.
- Support request parameters when no response is given.
- Better support for HTTP headers.
- Add module for building URI templates from path and operation parameters.
- Allow input to be either a loaded object or JSON/YAML string.
- Better JSON Schema reference handling via
json-schema-ref-parser
package. - Do not set resource titles.
- Use
summary
instead ofoperationId
for action titles. - Set a relation value based on
operationId
for actions.
- Initial release.