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

Typescript API Requires Credentials by Default when Documentation Says Otherwise #1416

Closed
2 tasks done
xxmissingnoxx opened this issue Jun 11, 2022 · 4 comments
Closed
2 tasks done
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@xxmissingnoxx
Copy link

Before filling a bug

  • have you checked the faq for known issues.
  • have you checked existing issues

Expected behavior
According to the documentation , the default behavior for generating a Typescript client should be for --add-credentials=false, but it appears to require credentials if you fail to explicitly add that flag. The documentation says "Is called --add-credentials. Defaults to false."

The autorest command used was:
autorest --input-file=regular_error.yaml --typescript --output-folder=autorest/regular_error/typescript --clear-output-folder --generate-metadata=true

OpenAPI file is:

openapi: 3.0.3
info:
  title: Your Project API
  version: 1.0.0
  description: Using name clash Error type
paths:
  /blog/api/blogs/:
    get:
      operationId: blogs_list
      description: Paginated list of blogs and relevant metadata.
      parameters:
      - name: page
        required: false
        in: query
        description: A page number within the paginated result set.
        schema:
          type: integer
      - name: size
        required: false
        in: query
        description: Number of results to return per page.
        schema:
          type: integer
      tags:
      - blogs
      security:
      - cookieAuth: []
      - basicAuth: []
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaginatedPostList'
          description: ''
    post:
      operationId: blogs_create
      tags:
      - blogs
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Input'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Input'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Input'
        required: true
      security:
      - cookieAuth: []
      - basicAuth: []
      responses:
        '204':
          description: Success
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: ''
  /blog/api/schema/:
    get:
      operationId: schema_retrieve
      description: |-
        OpenApi3 schema for this API. Format can be selected via content negotiation.

        - YAML: application/vnd.oai.openapi
        - JSON: application/vnd.oai.openapi+json
      parameters:
      - in: query
        name: format
        schema:
          type: string
          enum:
          - json
          - yaml
      - in: query
        name: lang
        schema:
          type: string
          enum:
          - af
          - ar
          - ar-dz
          - ast
          - az
          - be
          - bg
          - bn
          - br
          - bs
          - ca
          - cs
          - cy
          - da
          - de
          - dsb
          - el
          - en
          - en-au
          - en-gb
          - eo
          - es
          - es-ar
          - es-co
          - es-mx
          - es-ni
          - es-ve
          - et
          - eu
          - fa
          - fi
          - fr
          - fy
          - ga
          - gd
          - gl
          - he
          - hi
          - hr
          - hsb
          - hu
          - hy
          - ia
          - id
          - ig
          - io
          - is
          - it
          - ja
          - ka
          - kab
          - kk
          - km
          - kn
          - ko
          - ky
          - lb
          - lt
          - lv
          - mk
          - ml
          - mn
          - mr
          - ms
          - my
          - nb
          - ne
          - nl
          - nn
          - os
          - pa
          - pl
          - pt
          - pt-br
          - ro
          - ru
          - sk
          - sl
          - sq
          - sr
          - sr-latn
          - sv
          - sw
          - ta
          - te
          - tg
          - th
          - tk
          - tr
          - tt
          - udm
          - uk
          - ur
          - uz
          - vi
          - zh-hans
          - zh-hant
      tags:
      - schema
      security:
      - cookieAuth: []
      - basicAuth: []
      - {}
      responses:
        '200':
          content:
            application/vnd.oai.openapi:
              schema:
                type: object
                additionalProperties: {}
            application/yaml:
              schema:
                type: object
                additionalProperties: {}
            application/vnd.oai.openapi+json:
              schema:
                type: object
                additionalProperties: {}
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
components:
  schemas:
    Error:
      type: object
      properties:
        code:
          type: string
          description: One of a server-defined set of error codes
        message:
          type: string
          description: A human-readable representation of the error
        target:
          type: string
          description: The target of the error
        details:
          type: array
          items:
            $ref: '#/components/schemas/Error'
          description: An array of details about specific errors that led to this
            reported error
        innererror:
          allOf:
          - $ref: '#/components/schemas/InnerError'
          description: An object containing more specific information than the current
            object about the error
      required:
      - code
      - message
    ErrorResponse:
      type: object
      properties:
        error:
          allOf:
          - $ref: '#/components/schemas/Error'
          description: The error object
      required:
      - error
    InnerError:
      type: object
      properties:
        code:
          type: string
          description: A more specific error code than was provided by the container
            error.
        innererror:
          allOf:
          - $ref: '#/components/schemas/InnerError'
          nullable: true
          description: An object containing more specific information than the current
            object about the error
      required:
      - innererror
    Input:
      type: object
      properties:
        blog_pk:
          type: integer
          minimum: 0
        description:
          type: string
          description: Enter comment about blog here.
          minLength: 2
      required:
      - blog_pk
      - description
    PaginatedPostList:
      type: object
      properties:
        count:
          type: integer
          example: 123
        next:
          type: string
          nullable: true
          format: uri
          example: http://api.example.org/accounts/?page=4
        previous:
          type: string
          nullable: true
          format: uri
          example: http://api.example.org/accounts/?page=2
        results:
          type: array
          items:
            $ref: '#/components/schemas/Post'
    Post:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        title:
          type: string
          readOnly: true
          description: Title of the post.
        post_date:
          type: string
          format: date-time
          readOnly: true
          description: Date and time at which the post was created.
        j_authors:
          type: array
          items:
            type: string
          description: Author(s) of the post.
          minItems: 1
      required:
      - id
      - j_authors
      - post_date
      - title
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
    cookieAuth:
      type: apiKey
      in: cookie
      name: sessionid

@ghost ghost added customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jun 11, 2022
@timotheeguerin timotheeguerin transferred this issue from Azure/autorest Jun 13, 2022
@sarangan12
Copy link
Member

Starting to work on this task. Will provide updates shortly.

@sarangan12 sarangan12 self-assigned this Jun 16, 2022
@sarangan12
Copy link
Member

Ok. I have done a quick analysis. The details are:

  1. In the Typescript SDK Generator, we set the addCredentials to true by default. If it has to be set to false, it has to be explicitly set. The specific piece of code is [Can be found here]:
async function getAddCredentials(
  host: AutorestExtensionHost
): Promise<boolean> {
  const addCredentials = await host.getValue("add-credentials");

  // Only set addCredentials to false if explicitly set to false
  // otherwise default to true
  if (addCredentials === false) {
    return false;
  } else {
    return true;
  }
}
  1. On the other hand, I understand the confusion as it was mentioned incorrectly here. This needs to be fixed. I will be creating a PR shortly to fix the documentation. Will update this issue, once I create the PR.

@sarangan12
Copy link
Member

I have created a PR to fix the documentation issue - Azure/autorest#4562. Will update this issue once the PR is approved and merged.

@sarangan12
Copy link
Member

The Documentation PR has been merged. No more action items pending on this issue. If you still face any issues, Please feel free to reopen this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

2 participants