Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backend API] Review current OpenAPI doc for linting #20

Closed
justinyoo opened this issue Jun 2, 2024 · 7 comments · Fixed by #229
Closed

[Backend API] Review current OpenAPI doc for linting #20

justinyoo opened this issue Jun 2, 2024 · 7 comments · Fixed by #229

Comments

@justinyoo
Copy link
Contributor

OpenAPI doc for the Backend API needs to be analysed

@justinyoo justinyoo changed the title OpenAPI doc linting [Backend API] OpenAPI doc linting Jun 2, 2024
@justinyoo
Copy link
Contributor Author

@justinyoo
Copy link
Contributor Author

justinyoo commented Aug 17, 2024

@justinyoo justinyoo changed the title [Backend API] OpenAPI doc linting [Backend API] Review current OpenAPI doc for linting Aug 17, 2024
@tae0y
Copy link
Contributor

tae0y commented Aug 17, 2024

asis 분석

  • swagger 설정 : src/AzureOpenAIProxy.ApiApp/Extensions/ServiceCollectionExtensions.cs > AddOpenApiService 부분에서 OpenAPI 설정을 함
  • 각 엔드포인트별 OpenAPI 설정 : src/AzureOpenAIProxy.ApiApp/Endpoints/WeatherForecastEndpoint.cs와 같이 엔드포인트별로 요청/응답을 어노테이션, 메서드 체인 등으로 설정함
    • src/AzureOpenAIProxy.ApiApp/Program.cs 설정한 엔드포인트를 app.AddWeatherForecast(); 구문과 같이 추가해줌

openapi 린팅 방법

  1. vscode/visual studio : spectral를 설치
  2. 앱을 구동한 뒤 swagger.json을 로컬에 다운받기
  3. 다운받은 swagger.json에서 린트되는 항목을 수정

openapi 적용방법

  • src/AzureOpenAIProxy.ApiApp/Endpoints/ChatCompletionsEndpoint.cs의 경우를 참조
// 요청 페이로드 정의
.Accepts<ChatCompletionOptions>(contentType: "application/json")
// 응답 페이로드 정의
.Produces<ChatCompletion>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
.Produces(statusCode: StatusCodes.Status401Unauthorized)
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
// 태그, 이름, 요약, 설명 등 기타항목 추가
.WithTags("openai")
.WithName("GetChatCompletions")
.WithOpenApi(operation =>
{
    operation.Summary = "Get chat completions";
    operation.Description = "Gets the chat completions";
    return operation;
});
  • 만약 빠뜨렸을 경우에는?
    1. 아래와 같이 태그 명명규칙을 빼먹으면
    2. 다운받은 swagger.json에 warning이 뜨고
    3. vscode의 경우 출력탭에서 spectral로 뷰를 설정하면
    4. warning 내용이 자세히 나온다
image

@tae0y
Copy link
Contributor

tae0y commented Aug 17, 2024

  • spectral 설정하면 openapi v2,3이 기본 적용됨
    • 정확히 openapi 3.0.1을 적용하는 방법은 조사필요
  • 현재 백엔드 엔드포인트는 OpenAPI 항목중에서 요청/응답 페이로드, 태그/이름/요약/설명을 정의중
    • 추가해야할 필수값이 있을지 팀에서 의논 필요

@justinyoo
Copy link
Contributor Author

@tae0y 스펙트럴에 built-in OpenAPI 룰셋이 있습니다. 그걸 적용하시면 됩니다: https://docs.stoplight.io/docs/spectral/4dec24461f3af-open-api-rules

아마도 어쩌면 커스텀 룰셋이 필요할 수도 있는데, 그 때는 요런 식으로 우리만의 룰셋 파일을 하나 만들어 보는 것도 나쁘지 않습니다: https://github.com/Azure-Samples/APICenter-Reference/blob/main/resources/rulesets/oas.yaml

만약 현재 자동으로 생성되는 OpenAPI 문서를 위의 built-in OpenAPI 룰셋으로 돌렸을 때 문제가 없다고 판단한다면, 커스텀 룰셋 하나만 만들어 보세요.

tae0y added a commit to tae0y/azure-openai-sdk-proxy that referenced this issue Aug 18, 2024
related to aliencube#20, aliencube#21
필수 필드를 지정하고, 해당 필드가 없을 경우 에러를 발생시키도록 수정
tae0y added a commit to tae0y/azure-openai-sdk-proxy that referenced this issue Aug 18, 2024
related to aliencube#20, aliencube#21
필수 필드를 지정하고, 해당 필드가 없을 경우 에러를 발생시키도록 수정
@tae0y
Copy link
Contributor

tae0y commented Aug 18, 2024

@justinyoo
현재 기준으로 weatherforecast, chat/completions에 지정된 필드들을 필수값으로 지정해서
없을 경우에는 error를 발생시키도록 해보았습니다~

@justinyoo justinyoo linked a pull request Aug 18, 2024 that will close this issue
@justinyoo
Copy link
Contributor Author

@tae0y PR에 코드리뷰 코멘트 남겼어욥

tae0y added a commit to tae0y/azure-openai-sdk-proxy that referenced this issue Aug 18, 2024
related to aliencube#20, aliencube#21
필수 필드를 지정하고, 해당 필드가 없을 경우 에러를 발생시키도록 수정
justinyoo pushed a commit that referenced this issue Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants