From 77cfb3d44258cd0158d83366e52a41694c72f7a3 Mon Sep 17 00:00:00 2001 From: RyoNakagawa Date: Thu, 19 Dec 2024 15:11:51 +0900 Subject: [PATCH] =?UTF-8?q?ADB2C=E3=83=97=E3=83=AD=E3=82=B8=E3=82=A7?= =?UTF-8?q?=E3=82=AF=E3=83=88=E3=81=ABProblemDetails=E3=81=AE=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C=E3=82=92=E5=8F=8D=E6=98=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api-docs/api-specification.json | 52 +++++++++++++--- .../web/controller/UserController.java | 3 +- .../ExceptionHandlerControllerAdvice.java | 4 +- .../api-client/.openapi-generator/FILES | 29 ++++----- .../src/generated/api-client/api/user-api.ts | 2 + .../src/generated/api-client/models/index.ts | 1 + .../api-client/models/problem-detail.ts | 60 +++++++++++++++++++ 7 files changed, 126 insertions(+), 25 deletions(-) create mode 100644 samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/models/problem-detail.ts diff --git a/samples/azure-ad-b2c-sample/auth-backend/api-docs/api-specification.json b/samples/azure-ad-b2c-sample/auth-backend/api-docs/api-specification.json index 62399d19f..8087eccf1 100644 --- a/samples/azure-ad-b2c-sample/auth-backend/api-docs/api-specification.json +++ b/samples/azure-ad-b2c-sample/auth-backend/api-docs/api-specification.json @@ -60,6 +60,13 @@ "description": "成功." }, "401": { + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetail" + } + } + }, "description": "未認証エラー." } }, @@ -77,27 +84,56 @@ }, "components": { "schemas": { - "TimeResponse": { + "ProblemDetail": { "type": "object", "properties": { - "serverTime": { + "detail": { "type": "string" + }, + "instance": { + "type": "string", + "format": "uri" + }, + "properties": { + "type": "object", + "additionalProperties": { + "type": "object" + } + }, + "status": { + "type": "integer", + "format": "int32" + }, + "title": { + "type": "string" + }, + "type": { + "type": "string", + "format": "uri" } - }, + } + }, + "TimeResponse": { "required": [ "serverTime" - ] + ], + "type": "object", + "properties": { + "serverTime": { + "type": "string" + } + } }, "UserResponse": { + "required": [ + "userId" + ], "type": "object", "properties": { "userId": { "type": "string" } - }, - "required": [ - "userId" - ] + } } }, "securitySchemes": { diff --git a/samples/azure-ad-b2c-sample/auth-backend/web/src/main/java/com/dressca/web/controller/UserController.java b/samples/azure-ad-b2c-sample/auth-backend/web/src/main/java/com/dressca/web/controller/UserController.java index b2417f41f..6a6e2c458 100644 --- a/samples/azure-ad-b2c-sample/auth-backend/web/src/main/java/com/dressca/web/controller/UserController.java +++ b/samples/azure-ad-b2c-sample/auth-backend/web/src/main/java/com/dressca/web/controller/UserController.java @@ -1,5 +1,6 @@ package com.dressca.web.controller; +import org.springframework.http.ProblemDetail; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.CrossOrigin; @@ -34,7 +35,7 @@ public class UserController { @SecurityRequirement(name = "Bearer") }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "成功.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = UserResponse.class))), - @ApiResponse(responseCode = "401", description = "未認証エラー.", content = @Content) + @ApiResponse(responseCode = "401", description = "未認証エラー.", content = @Content(mediaType = "application/problem+json", schema = @Schema(implementation = ProblemDetail.class))) }) @GetMapping diff --git a/samples/azure-ad-b2c-sample/auth-backend/web/src/main/java/com/dressca/web/controller/advice/ExceptionHandlerControllerAdvice.java b/samples/azure-ad-b2c-sample/auth-backend/web/src/main/java/com/dressca/web/controller/advice/ExceptionHandlerControllerAdvice.java index 1c2a3e12f..804b82d97 100644 --- a/samples/azure-ad-b2c-sample/auth-backend/web/src/main/java/com/dressca/web/controller/advice/ExceptionHandlerControllerAdvice.java +++ b/samples/azure-ad-b2c-sample/auth-backend/web/src/main/java/com/dressca/web/controller/advice/ExceptionHandlerControllerAdvice.java @@ -42,7 +42,7 @@ public ResponseEntity accessDeniedHandleException(AccessDeniedExc CommonExceptionIdConstant.E_BUSINESS, HttpStatus.UNAUTHORIZED); return ResponseEntity.status(HttpStatus.UNAUTHORIZED) - .contentType(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_PROBLEM_JSON) .body(problemDetail); } @@ -61,7 +61,7 @@ public ResponseEntity handleException(Exception e, HttpServletReq CommonExceptionIdConstant.E_SYSTEM, HttpStatus.INTERNAL_SERVER_ERROR); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .contentType(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_PROBLEM_JSON) .body(problemDetail); } } diff --git a/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/.openapi-generator/FILES b/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/.openapi-generator/FILES index 63d889f91..22748cd65 100644 --- a/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/.openapi-generator/FILES +++ b/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/.openapi-generator/FILES @@ -1,14 +1,15 @@ -.gitignore -.npmignore -.openapi-generator-ignore -api.ts -api/server-time-api.ts -api/user-api.ts -base.ts -common.ts -configuration.ts -git_push.sh -index.ts -models/index.ts -models/time-response.ts -models/user-response.ts +.gitignore +.npmignore +.openapi-generator-ignore +api.ts +api/server-time-api.ts +api/user-api.ts +base.ts +common.ts +configuration.ts +git_push.sh +index.ts +models/index.ts +models/problem-detail.ts +models/time-response.ts +models/user-response.ts diff --git a/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/api/user-api.ts b/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/api/user-api.ts index a758e6e79..8cd9ae5f1 100644 --- a/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/api/user-api.ts +++ b/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/api/user-api.ts @@ -22,6 +22,8 @@ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObj // @ts-ignore import { BASE_PATH, COLLECTION_FORMATS, type RequestArgs, BaseAPI, RequiredError, operationServerMap } from '../base'; // @ts-ignore +import type { ProblemDetail } from '../models'; +// @ts-ignore import type { UserResponse } from '../models'; /** * UserApi - axios parameter creator diff --git a/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/models/index.ts b/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/models/index.ts index a95a0ad25..5c01d1893 100644 --- a/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/models/index.ts +++ b/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/models/index.ts @@ -1,2 +1,3 @@ +export * from './problem-detail'; export * from './time-response'; export * from './user-response'; diff --git a/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/models/problem-detail.ts b/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/models/problem-detail.ts new file mode 100644 index 000000000..3de2e85e2 --- /dev/null +++ b/samples/azure-ad-b2c-sample/auth-frontend/app/src/generated/api-client/models/problem-detail.ts @@ -0,0 +1,60 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Azure AD B2C ユーザー認証 + * Azure AD B2Cを利用したユーザー認証機能を提供するサンプルアプリケーションです。 + * + * The version of the OpenAPI document: v1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface ProblemDetail + */ +export interface ProblemDetail { + /** + * + * @type {string} + * @memberof ProblemDetail + */ + 'detail'?: string; + /** + * + * @type {string} + * @memberof ProblemDetail + */ + 'instance'?: string; + /** + * + * @type {{ [key: string]: object; }} + * @memberof ProblemDetail + */ + 'properties'?: { [key: string]: object; }; + /** + * + * @type {number} + * @memberof ProblemDetail + */ + 'status'?: number; + /** + * + * @type {string} + * @memberof ProblemDetail + */ + 'title'?: string; + /** + * + * @type {string} + * @memberof ProblemDetail + */ + 'type'?: string; +} +