vrchatapi-rust icon indicating copy to clipboard operation
vrchatapi-rust copied to clipboard

Patch OpenAPI spec instead of writing custom code

Open 0xkubectl opened this issue 1 year ago • 3 comments

In https://github.com/vrchatapi/vrchatapi-rust/pull/12 custom code was introduced to fix https://github.com/vrchatapi/specification/issues/241. I have opened https://github.com/vrchatapi/specification/pull/352, but we noticed that some of the generators do not support the oneOf. Its reasonable to assume that this is on hold until upstream generators of all supported languages can deal with oneOf.

This change generates code that is similar to what was added manually but does this via patching the spec instead. IMHO this a more maintainable way of achieving the same goal. Please give feedback.

EDIT: Based on these DC Messages: One, Two I opted to use JSONPatch instead of a regular patch as it was mentioned they are quite hard to maintain.

0xkubectl avatar Jul 23 '24 20:07 0xkubectl

The dart package used to do this, so I see no issue

Rexios80 avatar Jul 23 '24 21:07 Rexios80

We could add this to the specification repository and, during bundling, create two specs. Generators that support oneOf can then use the feature-enabled spec.

ariesclark avatar Jul 23 '24 21:07 ariesclark

Something like:

/auth/user:
    get:
      summary: Login and/or Get Current User Info
      tags:
        - authentication
      x-codeSamples:
        $ref: "../codeSamples/authentication.yaml#/~1auth~1user/get"
      responses:
        '200':
          x-feature:
            key: oneOf
            schema: 
              oneOf:
                - $ref: ../responses/authentication/CurrentUserLoginResponse.yaml
                - $ref: '#/components/schemas/TwoFactorRequired'
            fallback:
              $ref: ../responses/authentication/CurrentUserLoginResponse.yaml
        '401':
          $ref: ../responses/MissingCredentialsError.yaml

then during bundling/building, we're turn this into two specification files.

ariesclark avatar Jul 23 '24 21:07 ariesclark

I think fixing this here is not a good solution at this point in time and is not implemented in a clean way. Closing for now.

0xkubectl avatar Sep 29 '24 20:09 0xkubectl