jHipster swagger api-doc not sending JWT authorization header resulting in 401 - jhipster

Generating a project with jhipster#6.2.0 with API-First development and JWT does not send the authorization header.
api.yml (default generated with addition of /api prefix and pet path/schema)
# API-first development with OpenAPI
# This file will be used at compile time to generate Spring-MVC endpoint stubs using openapi-generator
openapi: '3.0.1'
info:
title: 'temp2'
version: 0.0.1
servers:
- url: http://localhost:8080/api
description: Development server
- url: https://localhost:8080/api
description: Development server with TLS Profile
paths:
/pet/findByStatus:
get:
tags:
- pet
summary: Finds Pets by status
description: Multiple status values can be provided with comma separated strings
operationId: findPetsByStatus
responses:
200:
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
400:
description: Invalid status value
content: {}
components:
schemas:
Pet:
required:
- name
- photoUrls
type: object
properties:
id:
type: integer
format: int64
securitySchemes:
jwt:
type: http
description: JWT Authentication
scheme: bearer
bearerFormat: JWT
security:
- jwt: []
./mvnw generate-sources
./mvnw
Visit http://localhost:8080/admin/docs
The authorization header is sent for the account-resources GET /api/account
However it is not sent for the pet request GET /api/pet/findByStatus resulting in a 401 Unauthorized.

In src/main/webapp/swagger-ui/index.html
function addApiKeyAuthorization() {
var authToken = JSON.parse(localStorage.getItem("jhi-authenticationtoken") || sessionStorage.getItem("jhi-authenticationtoken"));
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("Authorization", "Bearer " + authToken, "header");
window.swaggerUi.api.clientAuthorizations.add("bearer", apiKeyAuth);
}
The clientAuthorization is added with the key "bearer" instead of the autogenerated "jwt".
Changing jwt to bearer resolves it
diff --git a/src/main/resources/swagger/api.yml b/src/main/resources/swagger/api.yml
index b259b3e..1f77650 100644
--- a/src/main/resources/swagger/api.yml
+++ b/src/main/resources/swagger/api.yml
## -42,10 +42,10 ## components:
type: integer
format: int64
securitySchemes:
- jwt:
+ bearer:
type: http
description: JWT Authentication
scheme: bearer
bearerFormat: JWT
security:
- - jwt: []
+ - bearer: []

Related

How to use node.js to implement multipart/form-data in openapi3's yaml file?

I'm setting up a new server and my goal is to implement multipart/form-data in OpenApi3.0's yaml file. I encounter "should NOT have additional properties (consume)" error in Node.js and wanna know how to fix this error or how to implement multipart/form-data in OpenApi3.0's yaml file?
This is my OpenApi3.0's yaml file to implement this goal, it will report the error I mentioned above.
openapi: 3.0.1
info:
title: myapp
description: My cool app
version: 1.0.0
servers:
- url: /api/v1/user
tags:
- name: User
description: User Operations
paths:
/onboarding/signature:
post:
tags:
- User
description: Onboarding Upload Signature API - with parameters user's email and image file
requestBody:
description: Request Body {email, image}
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/onboardingSignature'
required: true
responses:
200:
description: OK
201:
description: Created
400:
description: Bad Request
500:
description: Internal Server Error
components:
schemas:
onboardingSignature:
description: Onboarding Signature File
type: object
properties:
email:
type: string
image:
format: binary
I expect the implementation of uploading file in Swagger use multipart/form-data format.

swagger: requestBody not allowed

I'm trying to define a post endpoint using swagger, but it isn't allowing the requestBody parameter:
/names/{roster}:
get:
#...
post:
x-swagger-router-controller: names
description: Adds or removes name(s)
operationId: manageNames
parameters:
- name: roster
in: path
description: the roster to use
type: string
required: true
requestBody:
content:
'application/json':
schema:
$ref: '#/definitions/ManageNamesRequest'
when I run npm start, I get this:
API Errors:
#/paths/~1names~1{roster}/post: Additional properties not allowed: requestBody
1 error and 0 warnings
What's wrong with my spec?
You are probably mixing OpenAPI/Swagger 2.0 and OpenAPI 3.0 syntax. Your spec seems to be 2.0, but the requestBody keyword is a 3.0 feature. In 2.0, the request body is defined as a body parameter:
paths:
/names/{roster}:
post:
produces:
- application/json
...
parameters:
- ...
- in: body
name: body
required: true
schema:
$ref: '#/definitions/ManageNamesRequest'
More info: Describing Request Body

Setting HTTP Proxy on AWS API Gateway via Cloudformation

Thanks for the help in advance.
Currently using cloudformation templates to deploy a simple API to AWS as part of a POC for moving from Azure to AWS API management.
I have got everything working except i have not been able to figure out the YAML AWS extension for setting the HTTP proxy checkbox for the HTTP request.
Sample YAML below. I know this will not set that checkbox (as i have tested it and it worked minus that problem), but on this page
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-integration.html
i cannot see a extension that sets this option? Has AWS not done this yet
AWSTemplateFormatVersion: '2010-09-09'
Resources:
PlayersAPI:
Type: AWS::ApiGateway::RestApi
Properties:
Name: RAH API
Description: A demo API for testing
Body:
swagger: '2.0'
info:
title: test api
description: test api
version: 1.0.1
contact:
name: SH
email: test#mailinator.com
paths:
"/heartbeat":
get:
description: Checks the API is working
produces:
- application/json
responses:
'200':
description: API Response information
x-amazon-apigateway-integration:
type: http
responses:
default:
statusCode: '200'
httpMethod: GET
uri: https://api.example.com
This works for me:
resources:
Resources:
ProxyResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Fn::GetAtt:
- ApiGatewayRestApi # our default Rest API logical ID
- RootResourceId
PathPart: "{proxy+}" # the endpoint in your API that is set as proxy
RestApiId:
Ref: ApiGatewayRestApi
ProxyMethod:
Type: AWS::ApiGateway::Method
Properties:
ResourceId:
Ref: ProxyResource
RestApiId:
Ref: ApiGatewayRestApi
HttpMethod: GET # the method of your proxy. Is it GET or POST or ... ?
MethodResponses:
- StatusCode: 200
Integration:
IntegrationHttpMethod: GET
Type: HTTP_PROXY
Uri: http://bucket.mybucket.co.s3.eu-west-1.amazonaws.com/{proxy} # the URL you want to set a proxy to
IntegrationResponses:
- StatusCode: 200
AuthorizationType: NONE

Cannot resolve the configured swagger-router handler: movie_get

I'm using Swagger with NodeJS, and when I test an example I have this error.
Here is my YAML:
swagger: "2.0"
info:
version: "0.0.1"
title: Hello World App
# during dev, should point to your local machine
host: localhost:10010
# basePath prefixes all resource paths
basePath: /
#
schemes:
# tip: remove http to make production-grade
- http
- https
# format of bodies a client can send (Content-Type)
consumes:
- application/json
# format of the responses to the client (Accepts)
produces:
- application/json
paths:
/movie:
# our controller name
x-swagger-router-controller: movie
get:
description: get the movies list
# define the type of response for Success "200" and Error
responses:
"200":
description: Success
schema:
$ref: "#/definitions/GetMoviesListResponse"
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
/swagger:
x-swagger-pipe: swagger_raw
# complex objects have schema definitions
definitions:
GetMoviesListResponse:
required:
- movies
properties:
# The array of movies
movies:
type: array
items:
type: object
properties:
id:
type: string
title:
type: string
year:
type: number
ErrorResponse:
required:
- message
properties:
message:
type: string
Given your YAML, and assuming you're using swagger-tools with the options given in their tutorials, x-swagger-router-controller: movie will route any requests to GET /movie to a function called get exported from the module /controllers/movie.js in your project. Have you set that up?
Also check your swagger options to check that the correct controllers path is included, e.g. controllers: `${__dirname}`/controllers.

Swagger validation failed in Yaml file

I have a swagger yaml specification like this :
swagger: "2.0"
info:
version: "0.0.1"
title: Chat API
# during dev, should point to your local machine
host: localhost:5000
# basePath prefixes all resource paths
basePath: /api/v2
#
schemes:
# tip: remove http to make production-grade
- http
- https
# format of bodies a client can send (Content-Type)
consumes:
- application/json
# format of the responses to the client (Accepts)
produces:
- application/json
paths:
/room:
post:
summary: Get room
operationId: getRoom
tags:
- room
parameters:
-
name: token
in: header
description: "token to be passed as a header"
default: "ZjE4YjMxNmY3OGEzNDMyN2JiYjJmYTQwMDBjODg4OWM="
required: true
-
name: room_id
in: body
description: "get room"
required: true
schema:
$ref: "#/definitions/Room"
definitions:
Room:
required:
- room_id
properties:
room_id:
type: string
This yaml file is compiled well without the header part. If I include the header in the paramerts . The nodejs app keep throwing : "Swagger validation errors"
-
name: token
in: header
description: "token to be passed as a header"
default: "ZjE4YjMxNmY3OGEzNDMyN2JiYjJmYTQwMDBjODg4OWM="
required: true
I don't know what was wrong in this part. I want to add the header to this spec file.
You simply need to add the type attribute. Swagger doesn't know if this is a string, an integer, etc. (although one could say the default explains it).
- name: token
in: header
description: "token to be passed as a header"
default: "ZjE4YjMxNmY3OGEzNDMyN2JiYjJmYTQwMDBjODg4OWM="
required: true
type: string

Resources