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

Validation failure #341

Closed
tumkurrunner opened this issue Jul 24, 2020 · 5 comments
Closed

Validation failure #341

tumkurrunner opened this issue Jul 24, 2020 · 5 comments

Comments

@tumkurrunner
Copy link

tumkurrunner commented Jul 24, 2020

Description:
Problem using Inheritance model
I have a base type Activity and Subtypes SubActivity1 SubActivity2 & SubActivity3 with discriminator propertyName set correct but still I get an error request should match exactly one schema in oneOf. Just to make if the spec is valid I tried https://bitbucket.org/atlassian/swagger-request-validator/src and validation is successful.

I have added the test yaml for reference.

openapi: 3.0.1
info:
  title: OpenAPI definition
  version: v0
servers:
  - url: 'http://localhost:8086'
    description: Generated server url
paths:
  /test/api1:
    post:
      tags:
        - test-controller
      summary: Find something
      description: Do work
      operationId: getDecision
      requestBody:
        content:
          application/vnd.api+json:
            schema:
              $ref: '#/components/schemas/DecisionRequestDocument'
        required: true
      responses:
        '201':
          description: Created
          content:
            application/vnd.api+json:
              schema:
                $ref: '#/components/schemas/DecisionResponseDocument'
components:
  schemas:
    DecisionResponse:
      required:
        - executionTimestamp
      type: object
      properties:
        name:
          maxLength: 50
          minLength: 1
          pattern: '^([ -$&-9:;=@-Z\x5e-z¡-£\xC0-\uFFFD]){1,50}$'
          type: string
          description: test name
        version:
          maxLength: 50
          minLength: 1
          pattern: '^([ -$&-9:;=@-Z\x5e-z¡-£\xC0-\uFFFD]){1,50}$'
          type: string
          description: version desc
        executionTimestamp:
          type: string
          description: RFC3339 format.
          format: date-time
          example: 2018-05-19T10:23:00.000Z
    DecisionResponseDocument:
      required:
        - data
      type: object
      properties:
        data:
          $ref: '#/components/schemas/DecisionResponseResourceObject'
    DecisionResponseResourceObject:
      required:
        - attributes
        - type
      type: object
      properties:
        type:
          maxLength: 240
          minLength: 1
          pattern: '^[a-zA-Z0-9\-\.\s]{1,240}$'
          type: string
        attributes:
          $ref: '#/components/schemas/DecisionResponse'
        id:
          maxLength: 36
          minLength: 36
          pattern: >-
            ^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          type: string
    DecisionDetails:
      required:
        - decisionAdvice
      type: object
      properties:
        decisionAdvice:
          type: string
          description: Decide
          enum:
            - APPROVED
            - DECLINED
      description: test details
    TRY_ACTIVATION:
      required:
        - timestamp
        - type
      type: object
      description: Try activation activity
      allOf:
        - $ref: '#/components/schemas/Activity'
    Activity:
      required:
        - timestamp
        - type
      type: object
      properties:
        type:
          type: string
          enum:
            - PURCHASE
            - TRY_ACTIVATION
            - LOGIN
        timestamp:
          type: string
          description: RFC3339 format.
          format: date-time
          example: 2018-05-19T10:23:00.000Z
        accountId:
          maxLength: 20
          minLength: 1
          pattern: '^[0-9]{1,10}$'
          type: string
      description: The base type for an activity
      discriminator:
        propertyName: type
        mapping:
          PURCHASE: '#/components/schemas/PURCHASE'
          LOGIN: '#/components/schemas/LOGIN'
          TRY_ACTIVATION: '#/components/schemas/TRY_ACTIVATION'
    DecisionRequest:
      required:
        - activity
        - actor
      type: object
      properties:
        activity:
          oneOf:
            - $ref: '#/components/schemas/PURCHASE'
            - $ref: '#/components/schemas/LOGIN'
            - $ref: '#/components/schemas/TRY_ACTIVATION'
    DecisionRequestDocument:
      required:
        - data
      type: object
      properties:
        data:
          $ref: '#/components/schemas/DecisionRequestResourceObject'
    DecisionRequestResourceObject:
      required:
        - attributes
        - type
      type: object
      properties:
        type:
          maxLength: 240
          minLength: 1
          pattern: '^[a-zA-Z0-9\-\.\s]{1,240}$'
          type: string
        attributes:
          $ref: '#/components/schemas/DecisionRequest'
        id:
          maxLength: 36
          minLength: 36
          pattern: >-
            ^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          type: string
    LOGIN:
      required:
        - password
        - timestamp
        - type
        - username
      type: object
      description: Login activity
      allOf:
        - $ref: '#/components/schemas/Activity'
        - type: object
          properties:
            username:
              maxLength: 30
              minLength: 6
              pattern: '^([ -$&-9:;=@-Z\x5e-z¡-£\xC0-\uFFFD]){1,50}$'
              type: string
              description: Username for online account access
            password:
              pattern: '^([ -$&-9:;=@-Z\x5e-z¡-£\xC0-\uFFFD]){1,50}$'
              type: string
              description: Password for online account access
    PURCHASE:
      required:
        - cost
        - testname
        - reference
        - timestamp
        - type
      type: object
      description: online purchase activity
      allOf:
        - $ref: '#/components/schemas/Activity'
        - type: object
          properties:
            testname:
              maxLength: 100
              minLength: 1
              pattern: '^((?![~%:;?<>\[\]{}|^\\])[\s\S]){1,100}$'
              type: string
            reference:
              maxLength: 50
              minLength: 1
              pattern: '^[A-Za-z0-9-_]{1,50}$'
              type: string
            cost:
              type: object
              properties:
                amount:
                  type: number
                currency:
                  type: string
@cdimascio
Copy link
Owner

cdimascio commented Aug 14, 2020

@tumkurrunner can you provide the example request
also, i see that the DecisionRequest requires actor, but actor is not defined as a property anywhere.

it would be good to solve these issues first i.e. that one noted above. also, it will be great if you can provide a canonical version of this spec with the minimum to reveal the error. it will certainly help to make the investigation simpler.

@GiriMPT
Copy link

GiriMPT commented Aug 14, 2020

Don't worry I found a work around, I got the answer from here OAI/OpenAPI-Specification#2141 (comment).

@cdimascio
Copy link
Owner

@tumkurrunner i'm working on an initial version of discriminator support. it will start by supporting top level types. will expand it to this use case. #461

@Hono76
Copy link

Hono76 commented May 12, 2022

I am trying to use the discriminator feature .What's the actual state regarding this matter? Can anyone shed some light on it?
Is it supported on validator ?

@cdimascio
Copy link
Owner

Closing as it is a Duplicate of the following #104

Additionally, top level (not full discriminator) discriminator support exist exists #461

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

No branches or pull requests

4 participants