LucyBot-Inc / api-spec-converter

Convert API descriptions between popular formats such as OpenAPI(fka Swagger), RAML, API Blueprint, WADL, etc.
https://lucybot-inc.github.io/api-spec-converter/
MIT License
1.11k stars 180 forks source link

Fails to generate valid OpenAPI from API Blueprint #372

Open doobnet opened 11 months ago

doobnet commented 11 months ago

I'm trying to convert an API Blueprint document to OpenAPI. No errors are generated but the resulting OpenAPI document doesn't seem to be valid.

Here's a minmal test case of an API Blueprint document that fails:

FORMAT: 1A
HOST: http://127.0.0.1/api/v1

# Group Extensions

## Extensions [/extensions]

### Get extensions [GET]

+ Response 200 (application/json)
    + Attributes (Extension)

## Data Structures

### Extension (enum)

+ (Foo type)

### Foo type (object, fixed-type)

+ id (string) - the id

The resulting OpenAPI document is:

openapi: 3.0.0
info:
  description: ''
  title: ''
  version: ''
servers:
  - url: 'http://127.0.0.1/api/v1'
paths:
  /extensions:
    get:
      responses:
        '200':
          content:
            application/json:
              examples:
                response:
                  value:
                    id: ''
              schema:
                enum:
                  - id: ''
                type: extend
          description: OK
          headers: {}
      tags:
        - Extensions
      description: ''
      summary: Get extensions
components:
  schemas:
    Extension:
      enum: []
      type: Foo type
    Extensions: {}
    Foo_type:
      properties:
        id:
          description: the id
          type: string
      type: object
tags:
  - name: Extensions

I used the following command to run api-spec-converter:

api-spec-converter -f api_blueprint -t openapi_3 -s yaml example.md > openapi.yaml

Validating the OpenAPI document using an online validating tool [1] gives the following errors:

Swagger schema validation failed.
  #/paths/~1extensions/get/responses/200/content/application~1json/schema/type must be equal to one of the allowed values
  #/paths/~1extensions/get/responses/200/content/application~1json/schema must have required property '$ref'
  #/paths/~1extensions/get/responses/200/content/application~1json/schema must match exactly one schema in oneOf
  #/paths/~1extensions/get/responses/200 must have required property '$ref'
  #/paths/~1extensions/get/responses/200 must match exactly one schema in oneOf
  #/components/schemas/Extension/enum must NOT have fewer than 1 items
  #/components/schemas/Extension/type must be equal to one of the allowed values
  #/components/schemas/Extension must have required property '$ref'
  #/components/schemas/Extension must match exactly one schema in oneOf

o@https://apitools.dev/swagger-parser/online/js/bundle.min.js:1:95569
@https://apitools.dev/swagger-parser/online/js/bundle.min.js:29:45045

o@https://apitools.dev/swagger-parser/online/js/bundle.min.js:1:95569
validateSchema@https://apitools.dev/swagger-parser/online/js/bundle.min.js:1:6328
@https://apitools.dev/swagger-parser/online/js/bundle.min.js:1:3405

[1] https://apitools.dev/swagger-parser/online/