Skip to content

[BUG] I write component object of OAS3 to external file. But error occured. Why? #3347

@yuji38kwmt

Description

@yuji38kwmt

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I write component object of OAS3 to external file.
I execute validate command for OAS3 file, but the following error occured.

Errors:
	-attribute paths.'/pets'(post).responses.default.content.schema.#/components/schemas/Error is missing
	-attribute paths.'/pets/{petId}'(get).responses.200.content.schema.#/components/schemas/Pets is missing
	-attribute components.$ref is unexpected
	-attribute paths.'/pets'(get).responses.default.content.schema.#/components/schemas/Error is missing
	-attribute paths.'/pets'(get).responses.200.content.schema.#/components/schemas/Pets is missing
	-attribute paths.'/pets/{petId}'(get).responses.default.content.schema.#/components/schemas/Error is missing
openapi-generator version

v 4.0.3

OpenAPI declaration file content or url

petstore-parent.yaml

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
    post:
      summary: Create a pet
      operationId: createPets
      tags:
        - pets
      responses:
        '201':
          description: Null response
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - animals
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  $ref: "./petstore-child.yaml"

petstore-child.yaml

schemas:
  Pet:
    required:
      - id
      - name
    properties:
      id:
        type: integer
        format: int64
      name:
        type: string
      tag:
        type: string
  Pets:
    type: array
    items:
      $ref: "#/schemas/Pet"
  Error:
    required:
      - code
      - message
    properties:
      code:
        type: integer
        format: int32
      message:
        type: string
Command line used for generation
$  java --version
openjdk 11.0.3 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu218.04.1)
OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu218.04.1, mixed mode, sharing)

$ java -jar ../openapi-generator-cli-4.0.3.jar validate -i petstore-parent.yaml 
Validating spec (petstore-parent.yaml)
Errors:
	-attribute paths.'/pets'(post).responses.default.content.schema.#/components/schemas/Error is missing
	-attribute paths.'/pets/{petId}'(get).responses.200.content.schema.#/components/schemas/Pets is missing
	-attribute components.$ref is unexpected
	-attribute paths.'/pets'(get).responses.default.content.schema.#/components/schemas/Error is missing
	-attribute paths.'/pets'(get).responses.200.content.schema.#/components/schemas/Pets is missing
	-attribute paths.'/pets/{petId}'(get).responses.default.content.schema.#/components/schemas/Error is missing


Question

Why did the error occur?
ReDoc can start HTTP server from above yaml file.

$ npx redoc-cli --version
0.8.4
$ npx redoc-cli serve petstore-parent.yaml 

image

Are above yaml file correct as OAS3?

Extra

The following yaml file is valid according to validate command of OpenAPI Generator.
Why did no error occur ?

petstore-parent.yaml

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
                $ref: "./petstore_child.yaml#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "./petstore_child.yaml#/components/schemas/Error"
    post:
      summary: Create a pet
      operationId: createPets
      tags:
        - pets
      responses:
        '201':
          description: Null response
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "./petstore_child.yaml#/components/schemas/Error"
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - animals
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: "./petstore_child.yaml#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "./petstore_child.yaml#/components/schemas/Error"

petstore-child.yaml

components:
  schemas:
    Pet:
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Pets:
      type: array
      items:
        $ref: "#/components/schemas/Pet"
    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

By the way I issued to OAI/OpenAPI-Specification#1972 .

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions