question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Required Header Param Resets State without Executing

See original GitHub issue

Q&A (please complete the following information)

  • OS: macOS High Sierra
  • Browser: Google Chrome
  • Version: Version 68.0.3440.106 (Official Build) (64-bit)
  • Method of installation: npm
  • Swagger-UI version: 3.18.2
  • Swagger/OpenAPI version: OpenAPI 3.0.0

Content & configuration

Example Swagger/OpenAPI definition:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Required Header State Reset Example
  description: Required header resets state when executing with try it out button.
  termsOfService: http://swagger.io/terms/
  contact:
    name: Swagger API Team
    email: apiteam@swagger.io
    url: http://swagger.io
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: '....'
security:
  - ApiKeyAuth: []
paths:
  /tags:
    get:
      description: Returns all tags.
      operationId: getTags
      parameters:
        - name: workspace
          in: header
          description: workspace identifier
          required: true
          schema:
            type: string
        - name: startIndex
          in: query
          description: offset to start from
          required: false
          schema:
            type: integer
            format: int32
        - name: stopIndex
          in: query
          description: maximum number of results to return
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: tags response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Tag'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization

  schemas:
    Tag:
      allOf:
        - $ref: '#/components/schemas/TagModel'
        - required:
          - id
          properties:
            id:
              type: integer
              format: int32

    TagModel:
      required:
        - name
      properties:
        name:
          type: string

    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

Swagger-UI configuration options:

const ui = SwaggerUI({
  url: `${axios.defaults.baseURL}/endpoints`,
  domNode: this.swaggerUI.current,
  // Using this: https://github.com/swagger-api/swagger-ui/blob/master/docs/customization/custom-layout.md
  plugins: [ OperationsLayoutPlugin ],
  layout: "OperationsLayout",
  onComplete: () => {
    ui.preauthorizeApiKey('ApiKeyAuth', sessionStorage.getItem('token'))
   },
})

Describe the bug you’re encountering

When a required header is added to list of parameters the state is reset when Execute is clicked.

To reproduce…

Steps to reproduce the behavior:

  1. Go to endpoints with a required header.
  2. Click on Try It Out
  3. Provide values for the params.
  4. Click on Execute
  5. See the state reset and no request executed.

Expected behavior

The request is executed and includes use of the required header.

Screenshots

2018-08-30 12 56 23

Additional context or thoughts

Setting the header param to required: false executes the request, but doesn’t include the header.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
shockeycommented, Sep 6, 2018

@calmdev, you’re correct - React 16 currently has some problems with Swagger UI.

Check back in a couple of months: we’re currently having some internal discussions about creating a specific flavor of the UI/Editor module for React users, which exposes a component that you can use regardless of your React version.

0reactions
calmdevcommented, Sep 6, 2018

That’d be great. I’ll keep any eye out for it. For now, I’ve forked the repo to create a custom standalone build that’s loaded using an iframe.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP/1.1: Header Field Definitions
Indicates that the client is willing to accept a response whose freshness lifetime is no less than its current age plus the specified...
Read more >
Intercept @RequestHeader exception for missing header
The response when you access your API without the required request header is: Missing request header 'Authorization' for method parameter of type String....
Read more >
Strict-Transport-Security - HTTP - MDN Web Docs
Whenever the Strict-Transport-Security header is delivered to the browser, it will update the expiration time for that site, so sites can ...
Read more >
HTTP headers and query string parameters for XML API
Without the Authorization header, you receive a MissingSecurityHeader error and your request is rejected. For more information about accessing Cloud Storage ...
Read more >
Troubleshooting | React Navigation
If you're testing on iOS and use Mac, make sure you have run pod install in the ... local component state or the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found