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

Support oneOf #32

Open
ferranpujolcamins opened this issue May 2, 2020 · 2 comments
Open

Support oneOf #32

ferranpujolcamins opened this issue May 2, 2020 · 2 comments

Comments

@ferranpujolcamins
Copy link

Given the following schema:

openapi: 3.0.2
info:
  version: 0.7.1
  title: aoide
  description: Music library management
  license:
    name: AGPL-3.0-or-later
    url: 'https://www.gnu.org/licenses/agpl-3.0.html'
paths:
  /date:
    get:
      summary: Get current date
      operationId: date
      parameters:
        - $ref: '#/components/schemas/WRAPPER'
      responses:
        '400':
          $ref: '#/components/schemas/YYYYMMDD'
components:
  schemas:
    WRAPPER:
      oneOf:
        - $ref: '#/components/schemas/YYYYMMDD'
    YYYYMMDD:
      type: object
      required:
        - value
      properties:
              value:
                 type: integer
                 format: int32

The YYYYMMDD struct is generated correctly. But then, bow-openapi generates two empty structs WRAPPER and OneOfWRAPPER.

I would expect WRAPPER to be an enum with a case with an associated value of YYYYMMDD.

@truizlop
Copy link
Member

truizlop commented May 4, 2020

Thanks for reporting! We'll take a look, but it may be due to the underlying tool we are using.

@miguelangel-dev
Copy link
Member

Ey @ferranpujolcamins ! You are putting on limit the library, nice!

Currently, we do not support OneOf, but you can use enum; I know you can not use it with associated complex types, but maybe you can find a workaround (think about it as DTO)... I will show you an example:

Given the next Apple SignIn service: https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens

You can look at the field grant_type, defined as enum in order to restrict possibilities for requests.

AppleSignInAuth:
      type: object
      required:
        - client_id
        - client_secret
        - grant_type
        - code
        - redirect_uri
      properties:
        client_id:
          type: string
          description: The application identifier for your app.
        client_secret:
          type: string
          description: A secret generated as a JSON Web Token that uses the secret key generated by the WWDR portal.
        grant_type:
          type: string
          description: The grant type that determines how the client interacts with the server. For authorization code validation, use authorization_code. For refresh token validation requests, use refresh_token.
          enum:
            - authorization_code
            - refresh_token
        code:
          type: string
          description: The authorization code received from your application’s user agent. The code is single use only and valid for five minutes.
        redirect_uri:
          type: string
          description: The destination URI the code was originally sent to. It must include a domain name, and can’t be an IP address or localhost.

Another example, in the response: https://developer.apple.com/documentation/sign_in_with_apple/errorresponse

We could define the error as

AppleSignInError:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: A string that describes the reason for the unsuccessful request. The string consists of a single allowed value.
          enum: 
            - invalid_request
            - invalid_client
            - invalid_grant
            - unauthorized_client
            - unsupported_grant_type
            - invalid_scope

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

3 participants