치명적 : 모든 작업에 OperationId가 필요합니다. 경로의 '가져 오기'작업을 위해 추가하십시오

Kirsten Greed

AutoRest를 사용하여 swagger.json에서 API의 클라이언트 측을 생성하고 있습니다.

출력은

AutoRest code generation utility [cli version: 3.0.6187; node: v10.16.3, max-memory: 8192 gb]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
NOTE: AutoRest core version selected from configuration: ~2.0.4413.
   Loading AutoRest core      'C:\Users\kirst\.autorest\@[email protected]\node_modules\@microsoft.azure\autorest-core\dist' (2.0.4417)
   Loading AutoRest extension '@microsoft.azure/autorest.csharp' (~2.3.79->2.3.82)
   Loading AutoRest extension '@microsoft.azure/autorest.modeler' (2.3.55->2.3.55)
FATAL: OperationId is required for all operations. Please add it for 'get' operation of '/api/Test' path.
FATAL: AutoRest.Core.Logging.CodeGenerationException: OperationId is required for all operations. Please add it for 'get' operation of '/api/Test' path.
   at AutoRest.Modeler.SwaggerModeler.Build(ServiceDefinition serviceDefinition) in /opt/vsts/work/1/s/src/SwaggerModeler.cs:line 96
   at AutoRest.Modeler.Program.<ProcessInternal>d__2.MoveNext() in /opt/vsts/work/1/s/src/Program.cs:line 60
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NewPlugin.<Process>d__15.MoveNext()
FATAL: csharp/imodeler1 - FAILED
FATAL: Error: Plugin imodeler1 reported failure.
Process() cancelled due to exception : Plugin imodeler1 reported failure.
  Error: Plugin imodeler1 reported failure.

swagger.json에 operationId에 대한 언급이 없음을 알았습니다.

그러나 나는 그것을 API에 언급했다.

    [AllowAnonymous]
    [HttpGet("Test")]
    [SwaggerOperation(OperationId = "Test")]

    public IActionResult Test()
    {

[최신 정보]

netcore3.1 및 AutoRest 3을 사용하도록 솔루션을 업그레이드하는 동안 Swagger Attribute Hell에서 2 일을 보냈습니다.

클라이언트 코드를 생성하기 위해 값 컨트롤러에 어떤 속성을 추가해야하는지 알 수 있습니다.

[Route("api/[controller]")]
[Produces("application/json")]
public class ValuesController : Controller
{
    public ValuesController()
    {
    }

    [HttpGet()]
    [Produces("application/json")]
    public IEnumerable<string> Get()
    {
        return new string[] {"value1", "value2"};
    }

    [Produces("application/json")]
    [HttpGet("{id}")]
    public string Get(int id)
    {
        return "value";
    }

    [HttpPost()]
    public void Post([FromBody] string value)
    {
    }

    // PUT api/values/5
    [HttpPut("{id}")]
    public void Put(int id, [FromBody] string value)
    {
    }

    // DELETE api/values/5
    [HttpDelete("{id}")]
    public void Delete(int id)
    {
    }
}

나는 사용하고있다

autorest --v3 --input-file=https://mywebsite/myapi/v1/swagger.json --output-folder=generated --csharp --namespace=myconnector

출력은

AutoRest code generation utility [cli version: 3.0.6187; node: v12.16.1, max-memory: 8192 gb]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
   Loading AutoRest core      'C:\Users\kirst\.autorest\@[email protected]\node_modules\@autorest\core\dist' (3.0.6262)
   Loading AutoRest extension '@microsoft.azure/autorest.csharp' (~2.3.79->2.3.84)
   Loading AutoRest extension '@microsoft.azure/autorest.modeler' (2.3.55->2.3.55)
FATAL: OperationId is required for all operations. Please add it for 'get' operation of '/api/Values' path.
FATAL: AutoRest.Core.Logging.CodeGenerationException: OperationId is required for all operations. Please add it for 'get' operation of '/api/Values' path.
   at AutoRest.Modeler.SwaggerModeler.Build(ServiceDefinition serviceDefinition) in /opt/vsts/work/1/s/src/SwaggerModeler.cs:line 96
   at AutoRest.Modeler.Program.<ProcessInternal>d__2.MoveNext() in /opt/vsts/work/1/s/src/Program.cs:line 60
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NewPlugin.<Process>d__15.MoveNext()
  Error: Plugin imodeler1 reported failure.

API 코드에는 TargetFramework netcoreapp3.1, Swashbuckle.AspNetCore 5.2.0, FluentValidation 8.6.2가 있습니다.

내 API가 .net core 2.1에있을 때 모든 것이 작동했지만 .netstandard2 라이브러리를 호출하고 싶었으므로 내 API를 netcore3.1로 업그레이드했습니다.

문서는 불완전 보인다. Autorest에 대한 언급이 없습니다. 다른 코드 생성기를 시도해야할까요?

[최신 정보]

.netcore2.1 브랜치의 샘플 JSON API 테스트

.netcore3.1 브랜치의 샘플 JSON

netcore3.1 브랜치

그러나 netcore3.1 브랜치에서 내용을 변경했을 수 있으므로 비교가 공정하지 않을 수 있습니다.

이 관련 질문에 대한 샘플 저장소를 설정했으며 이에 대한 netcore2.1 브랜치를 설정할 것입니다.

Weichch

나는 기본적으로 최신 Swagger (5.2.1)가 문서에 따라 선택적 식별자OperationId 이기 때문에 작업을 생성하지 않는다고 생각 합니다.

operationId는 작업을 식별하는 데 사용되는 선택적 고유 문자열입니다. 제공되는 경우 이러한 ID는 API에 설명 된 모든 작업에서 고유해야합니다.

그러나 AutoRest는이를 사용하여 각 방법을 식별하는 것 같습니다. 사람들이 메서드를 식별하기 위해 작업 ID 대신 태그를 사용하도록 AutoRest를 구성하여이 문제를 해결Github 질문 / 문제를 발견했습니다 .

AutoRest는 operationId를 사용하여 주어진 API에 대한 클래스 이름 / 메서드 이름을 결정합니다.

태그를 사용하지 않거나 태그가 충분히 고유하지 않은 경우 Swagger에게 다음과 같이 생성 된 JSON에 작업 ID를 추가하도록 요청할 수 있습니다.

options.SwaggerDoc(...);

// Tell Swagger where to find operation ID.
// In this example, use the controller action name.
options.CustomOperationIds(
    d => (d.ActionDescriptor as ControllerActionDescriptor)?.ActionName);

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관