Carapacik / swagger_parser

Dart package that takes an OpenApi definition file and generates REST clients based on retrofit and data classes for your project.
https://pub.dev/packages/swagger_parser
MIT License
94 stars 43 forks source link

Cannot generate code with parameters in separate components #78

Closed ykaito21 closed 1 year ago

ykaito21 commented 1 year ago

If I directly embed the parameter in the path, I could generate code, but if I have a separate component, I couldn't generate code

      parameters:
        - $ref: '#/components/parameters/WebAPIKey'
Carapacik commented 1 year ago

Are you using YAML definition ?

ykaito21 commented 1 year ago

yes

Carapacik commented 1 year ago

Could you send that piece of the circuit in which the generation breaks down?

ykaito21 commented 1 year ago

The first one generate code, but the second get error with Uncaught TypeError: null: type 'minified:wm' is not a subtype of type 'minified:aE<String, dynamic>' I think I got error when I tried to use common parameters for multiple methods or paths because I also get an error when I use common parameters on multiple methods. I actually use your https://carapacik.github.io/swagger_parser/ not package. Thanks for your help and making a great package!

openapi: 3.0.0
info:
  version: "1.0.0"
  title: "Firebase Auth REST API"
  description: "Firebase Authentication via REST API for Email & Password Sign In"
paths:

  /v1/accounts:signInWithCustomToken:
    post:
      summary: "Exchange custom token for an ID and refresh token"
      operationId: "signInWithCustomToken"
      tags:
        - "Authentication"
      parameters:
        - name: "key"
          in: "query"
          required: true
          description: "The Web API Key of the Firebase project"
          schema:
            type: "string"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExchangeCustomTokenRequest'
      responses:
        '200':
          description: "Successfully exchanged custom token"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExchangeCustomTokenResponse'
        '400':
          $ref: '#/components/responses/ErrorResponse'

components:
  responses:
    ErrorResponse:
      description: "Error response"
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'

  schemas:
    ExchangeCustomTokenRequest:
      type: object
      properties:
        token:
          type: string
          description: "A Firebase Auth custom token."
        returnSecureToken:
          type: boolean
          description: "Whether or not to return an ID and refresh token."
      required:
        - token
        - returnSecureToken

    ExchangeCustomTokenResponse:
        type: object
        properties:
          idToken:
            type: string
            description: "A Firebase Auth ID token."
          refreshToken:
            type: string
            description: "A Firebase Auth refresh token."
          expiresIn:
            type: string
            description: "The number of seconds in which the ID token expires."

    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: "Error message."
            errors:
              type: array
              items:
                type: object
                properties:
                  message:
                    type: string
                  domain:
                    type: string
                  reason:
                    type: string
openapi: 3.0.0
info:
  version: "1.0.0"
  title: "Firebase Auth REST API"
  description: "Firebase Authentication via REST API for Email & Password Sign In"
paths:

  /v1/accounts:signInWithCustomToken:
    post:
      summary: "Exchange custom token for an ID and refresh token"
      operationId: "signInWithCustomToken"
      tags:
        - "Authentication"
      parameters:
        - $ref: '#/components/parameters/WebAPIKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExchangeCustomTokenRequest'
      responses:
        '200':
          description: "Successfully exchanged custom token"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExchangeCustomTokenResponse'
        '400':
          $ref: '#/components/responses/ErrorResponse'

components:
  parameters:
    WebAPIKey:
      name: "key"
      in: "query"
      required: true
      description: "The Web API Key of the Firebase project"
      schema:
        type: "string"

  responses:
    ErrorResponse:
      description: "Error response"
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'

  schemas:
    ExchangeCustomTokenRequest:
      type: object
      properties:
        token:
          type: string
          description: "A Firebase Auth custom token."
        returnSecureToken:
          type: boolean
          description: "Whether or not to return an ID and refresh token."
      required:
        - token
        - returnSecureToken

    ExchangeCustomTokenResponse:
        type: object
        properties:
          idToken:
            type: string
            description: "A Firebase Auth ID token."
          refreshToken:
            type: string
            description: "A Firebase Auth refresh token."
          expiresIn:
            type: string
            description: "The number of seconds in which the ID token expires."

    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: "Error message."
            errors:
              type: array
              items:
                type: object
                properties:
                  message:
                    type: string
                  domain:
                    type: string
                  reason:
                    type: string
Carapacik commented 1 year ago

Apparently you are inserting the parameters incorrectly. Where do you need to insert the Web API Key parameter? I understand you want to take the Web Api Key as a separate parameter into a separate entity while changing the schema manually?

ykaito21 commented 1 year ago

it's called Web Api Key, but it's just a query. Firebase Auth Rest Api use like https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=[API_KEY] Am I wrong?

Carapacik commented 1 year ago

Your first scheme was correct

ykaito21 commented 1 year ago

I think I got error when I tried to use common parameters for multiple methods or paths because I also get an error when I use common parameters on multiple methods.

Am I using common parameters incorrectly?

Carapacik commented 1 year ago

No, you use it correctly, it just hasn't been taken into account yet

Carapacik commented 1 year ago

I think you need to wait for these changes in the next version along with the change from #76