-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(api): documente l'API avec OpenApi
- Loading branch information
Showing
8 changed files
with
711 additions
and
14 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'openapi-explorer'; | ||
import React, { useEffect } from 'react'; | ||
// @ts-expect-error TS7016 | ||
import {reactEventListener} from 'openapi-explorer/dist/es/react' | ||
import { authParams } from 'src/services/auth-headers'; | ||
import config from 'src/utils/config'; | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace JSX { | ||
interface IntrinsicElements { | ||
'openapi-explorer': React.DetailedHTMLProps< | ||
React.HTMLAttributes<HTMLElement>, | ||
HTMLElement | ||
>; | ||
} | ||
} | ||
} | ||
export const OpenApiExplorerView = () => { | ||
|
||
|
||
const onRequestFunction = (data: {detail: { request: {headers: Record<string, string>}}}) => { | ||
data.detail.request.headers = { ...data.detail.request.headers, ...authParams()} | ||
}; | ||
|
||
// Necessary because react by default does not know how to listen to HTML5 events | ||
reactEventListener({ useEffect }, 'request', onRequestFunction); | ||
return ( | ||
<openapi-explorer | ||
hide-server-selection={true} | ||
hide-authentication={true} | ||
spec-url={`${config.apiEndpoint}/api/api-docs`} | ||
server-url={`${config.apiEndpoint}/api`} | ||
/> | ||
); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { OpenApiBuilder, OpenAPIObject } from 'openapi3-ts/oas31'; | ||
import { extendZodWithOpenApi, OpenApiGeneratorV31, OpenAPIRegistry } from '@asteasolutions/zod-to-openapi'; | ||
import { UserInfos } from '../../shared/schema/User/User'; | ||
import { z } from 'zod'; | ||
extendZodWithOpenApi(z); | ||
export const getOpenApiSchema = (): OpenAPIObject =>{ | ||
const registry = new OpenAPIRegistry(); | ||
|
||
registry.register('User', UserInfos) | ||
|
||
//FIXME utiliser le register ?! | ||
//FIXME supprimer OpenApiBuilder ?! | ||
const openApiGenerator = new OpenApiGeneratorV31(registry.definitions) | ||
const compo = openApiGenerator.generateComponents() | ||
|
||
const builder = OpenApiBuilder.create().addOpenApiVersion('3.1.0') | ||
.addTitle('Maestro API') | ||
.addPath('/users/{userId}/infos', { | ||
get: { | ||
summary: "Trouve un utilisateur par son id", | ||
operationId: "getUserById" , | ||
parameters:[ | ||
{ | ||
"name": "userId", | ||
"in": "path", | ||
"required": true, | ||
"description": "L'identifiant de l'utilisateur", | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
], | ||
} | ||
}) | ||
.getSpec() | ||
|
||
|
||
|
||
|
||
return {...builder, ...compo} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters