使用API-First开发和JWT不发送授权头来生成一个使用jhipster@6.2.0的项目。
api.yml (添加/api prefix和pet路径/模式的默认生成)
# 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授权头发送给帐户资源GET /api/account。

但是,它不会被发送给宠物请求GET /api/pet/findByStatus,从而导致401未经授权。

发布于 2019-09-01 17:55:52
在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);
}clientAuthorization是用键“承载”来添加的,而不是自动生成的"jwt“。
将jwt更改为bearer可解决此问题
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: []

https://stackoverflow.com/questions/57748298
复制相似问题