Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwaggerEditor@next: false positive in linting JSON Schema #4026

Closed
quizwedge opened this issue Apr 3, 2023 · 16 comments
Closed

SwaggerEditor@next: false positive in linting JSON Schema #4026

quizwedge opened this issue Apr 3, 2023 · 16 comments

Comments

@quizwedge
Copy link

Q&A (please complete the following information)

  • OS: macOS
  • Browser: Chrome
  • Version: 111.0.5563.110
  • Method of installation: None. This is at https://editor-next.swagger.io/
  • Swagger-UI version: Unknown
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.3
info:
  title: Test
  version: 1.0.0
components:
  schemas:
    ObjectOne:
      type: object
      properties:
        propertyOne:
          type: string
    ObjectTwo:
      type: object
      properties:
        propertyTwo:
          type: string
paths:
  /test:
    post:
      requestBody: 
        content:
          application/json:
            schema: 
              oneOf:
                - $ref: '#/components/schemas/ObjectOne'
                - $ref: '#/components/schemas/ObjectTwo'
        required: true
      responses:
        '204':
          description: Successful operation

Swagger-UI configuration options:
None

Describe the bug you're encountering

The editor shows an error on line 23 saying, "oneOf must be a non-empty array of schemas" but it is an array of schemas.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor-next.swagger.io/.
  2. Enter the YAML above.
  3. See error.

Expected behavior

No errors or warnings.

Screenshots

OAS

@char0n char0n changed the title False error on new Swagger Editor SwaggerEditor@next: false positive in linting JSON Schema Apr 7, 2023
@char0n
Copy link
Member

char0n commented Apr 7, 2023

@quizwedge,

Thanks for reporting this. I'm transferring this issue under swagger-editor repo.

@char0n char0n transferred this issue from swagger-api/swagger-ui Apr 7, 2023
@dennewbie
Copy link

I have the same issue

@diegorendon
Copy link

diegorendon commented Apr 26, 2023

I have the same issue too.
It also happens with allOf.

@jmo927
Copy link

jmo927 commented May 8, 2023

Same issue with anyOf, allOf, and oneOf

@char0n
Copy link
Member

char0n commented May 10, 2023

Underlying issue is swagger-api/apidom#2481

JSON Schemas needs to be consolidated within the apidom-ls package.

@xdubx
Copy link

xdubx commented May 17, 2023

Same here.

openapi: 3.0.0
servers:
  - url: "http://localhost:3000/api/v1"
    variables: {}
info:
  description: Test
  version: 1.0.0
  title: Test
paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'
      responses:
        '200':
          description: Updated
components:
  schemas:
    Dog:
      type: object
      properties:
        bark:
          type: boolean
        breed:
          type: string
          enum: [Dingo, Husky, Retriever, Shepherd]
    Cat:
      type: object
      properties:
        hunts:
          type: boolean
        age:
          type: integer

Line Description
15 oneOf must be a non-empty array of schemas

From the example https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/#anyof

@Brunnn
Copy link

Brunnn commented Jun 15, 2023

Any updates on this? this is stopping me from using the api-dom validator github action, because my definition is right, but the workflow just throws those "errors"...

"responses": {
  "200": {
      "description": "Ok",
      "content": {
          "application/json": {
              "schema": {
                  "allOf": [
                      {
                          "$ref": "#/components/schemas/CursorPaginationBase"
                      },
                      {
                          "properties": {
                              "data": {
                                  "type": "array",
                                  "items": {
                                      "$ref": "#/components/schemas/ProductResource"
                                  }
                              }
                          },
                          "type": "object"
                      }
                  ]
              }
          }
      }
  },

image

@char0n
Copy link
Member

char0n commented Jun 20, 2023

It looks like the main issue is with allOf, oneOf and anyOf keywords. I'll try to see if I can provide a quick bug fix for those (without doing all the lengthy consolidation effort).

@goors
Copy link

goors commented Jun 21, 2023

This makes problem in generator as well. If there is an error such as this, $ref properties will not be generated (swift5).

For example, in some model, among other stuff, I have:


"Text": {
     "type": "string"
},
"Data": {
    "type": "string"
},
"Level": {
    "nullable": true,
    "oneOf": [
         {
               "$ref": "#/components/schemas/UserAdventureLevel"
         }
     ]
}

Generator will ignore that $ref, and it will only generate properties before or after.

@char0n
Copy link
Member

char0n commented Jul 17, 2023

@goors, if by generator you're referring to the swagger-codegen please create an issue at that repo.

@frantuma
Copy link
Member

fixed by swagger-api/apidom#2987

@Brunnn
Copy link

Brunnn commented Jul 26, 2023

Is this really fixed? I've tested on https://editor-next.swagger.io/ the example usage of the oneOf presented in the docs:

openapi: "3.0.0"
info:
  title: Simple API overview
  version: 2.0.0
paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'
      responses:
        '200':
          description: Updated
components:
  schemas:
    Dog:
      type: object
      properties:
        bark:
          type: boolean
        breed:
          type: string
          enum: [Dingo, Husky, Retriever, Shepherd]
    Cat:
      type: object
      properties:
        hunts:
          type: boolean
        age:
          type: integer

Still giving the same error:
image

@char0n
Copy link
Member

char0n commented Jul 27, 2023

@Brunnn It's been fixed but haven't been released and deployed yet. ETA for release/deploy today/tommorow.

@char0n
Copy link
Member

char0n commented Aug 3, 2023

@char0n
Copy link
Member

char0n commented Aug 3, 2023

@Brunnn are you able to use api-dom validator github action now?

@Brunnn
Copy link

Brunnn commented Aug 3, 2023

Yes, its working perfect now! Thanks @char0n.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants