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

required property in referenced response #102

Closed
gbkwiatt opened this issue Jun 4, 2020 · 4 comments
Closed

required property in referenced response #102

gbkwiatt opened this issue Jun 4, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@gbkwiatt
Copy link

gbkwiatt commented Jun 4, 2020

In this scenario my required properties are checked in the main response, not in nested config object. So it fails validation
yaml:

/system/config:
 get ... 

responses:
        '200':
          description: Config list
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Config'
                  - $ref: '#/components/schemas/dataToken'

components:
  schemas:
   Config:
     type: object
      properties:
        systemName:
          type: string
     required:
        - systemName

if I change systemName to config on required, it passes validation. which menas doesnt matter where required is, it always checks from main response object ?

@gbkwiatt gbkwiatt added the bug Something isn't working label Jun 4, 2020
@rwalle61
Copy link
Collaborator

rwalle61 commented Jun 4, 2020

Hi @gbkwiatt, thanks for raising this.

What’s in your dataToken schema, and what’s the validation error you’re getting?

@gbkwiatt
Copy link
Author

gbkwiatt commented Jun 4, 2020

dataToken schema is just another properties which are fine in this case.
without it I get same errors

dataToken:
      type: object
      properties:
        errorMessage:
          type: string
          example: ''
        errorCode:
          type: string
          example: ''
          enum:
            - ''
        token:
          type: string
          example: hbGciOiJIUzI1NiIsInR5cCI6...

validation error just says response should have required systemName, which it does but in response.body.config.systemName, but it looks for systemName inside response.body instead.

@rwalle61
Copy link
Collaborator

rwalle61 commented Jun 4, 2020

Okay, it looks like this isn't a bug, and your response schema is slightly different to your response body.

Your response body has response.body.config.systemName, but your response schema currently does not actually mention a config property. (Calling your schema Config does not make a difference in this respect).

Try this response schema:

        content:
            application/json:
              schema:
                allOf:
                  - type: object
                    properties:
                      config:
                        $ref: '#/components/schemas/Config'
                  - $ref: '#/components/schemas/dataToken'

Does that resolve your error?

(And if you get another error to do with allOf, check you are using allOf correctly - see this explanation #46 (comment))

@gbkwiatt
Copy link
Author

gbkwiatt commented Jun 4, 2020

I just had a look after sleep, and you are so right I don't know how I missed that, I was so certain config is there. Well It was there before but I must messed up on some point and in my head it was always there ;) Thank you for pointing it out. Again 'user errors' and your module is great, saves so much coding

@gbkwiatt gbkwiatt closed this as completed Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants