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

Overlapping operationId problem #276

Open
seheon-cho opened this issue Nov 14, 2024 · 0 comments
Open

Overlapping operationId problem #276

seheon-cho opened this issue Nov 14, 2024 · 0 comments

Comments

@seheon-cho
Copy link

The test code and the created openapi3.yaml.

It's openapi3.yaml based on the above, and the problem I'm facing is that the first factor of the document() method of the class com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper comes from the combination of the identifier variable of the type String class in operationId.

I wrote the test through the MockMvc and Mockito libraries.

@DisplayName("fail 1")
@Test
void login_fail1() throws Exception {
    //given
    LoginRequest loginRequest = new LoginRequest(null, "aos", "loginId", "password", "82");

    //when
    when(authService.login(any()))
            .thenThrow(new BusinessException(AuthErrorCode.INVALID_DEVICE_TOKEN));

    //then
    mockMvc.perform(post("/auth/login")
                    .contentType("application/json")
                    .content(customObjectMapper.writeValueAsString(loginRequest))
            )
            .andExpect(status().isOk())
            .andExpect(jsonPath("$.success").value(false))
            .andExpect(jsonPath("$.message").value("Invalid device token."))
            .andExpect(jsonPath("$.code").value(3003))
            .andExpect(jsonPath("$.errorData").value(Matchers.nullValue()))
            .andDo(document(
                    "Hello world!",
                    getDocumentRequest(),
                    getDocumentResponse(),
                    requestFields(
                            fieldWithPath("deviceToken").type(JsonFieldType.NULL).description("device token"),
                            fieldWithPath("deviceType").type(JsonFieldType.STRING).description("device type"),
                            fieldWithPath("email").type(JsonFieldType.STRING).description("email"),
                            fieldWithPath("password").type(JsonFieldType.STRING).description("pw"),
                            fieldWithPath("region").type(JsonFieldType.STRING).description("region")
                    ),
                    responseFields(
                         fieldWithPath("success").type(JsonFieldType.NULL).description("success"),
                          fieldWithPath("message").type(JsonFieldType.STRING).description("message"),
                          fieldWithPath("code").type(JsonFieldType.STRING).description("code"),
                          fieldWithPath("errorData").type(JsonFieldType.NULL).description("errorData")
                    )
            ));
}

@DisplayName("fail 2")
@Test
void login_fail_2() throws Exception {
    //given
    LoginRequest loginRequest = new LoginRequest("deviceToken", "aos", "loginId", "password", "82");

    //when
    when(authService.login(any()))
            .thenThrow(new BusinessException(AuthErrorCode.ALREADY_CONVERTED_USER));

    //then
    mockMvc.perform(post("/auth/login")
                    .contentType("application/json")
                    .content(customObjectMapper.writeValueAsString(loginRequest))
            )
            .andExpect(status().isOk())
            .andExpect(jsonPath("$.success").value(false))
            .andExpect(jsonPath("$.message").value("test user."))
            .andExpect(jsonPath("$.code").value(3017))
            .andExpect(jsonPath("$.errorData").value(Matchers.nullValue()))
            .andDo(document(
                    "Nice to meet you!",
                    getDocumentRequest(),
                    getDocumentResponse(),
                    requestFields(
                            fieldWithPath("deviceToken").type(JsonFieldType.NULL).description("device token"),
                            fieldWithPath("deviceType").type(JsonFieldType.STRING).description("device type"),
                            fieldWithPath("email").type(JsonFieldType.STRING).description("email"),
                            fieldWithPath("password").type(JsonFieldType.STRING).description("pw"),
                            fieldWithPath("region").type(JsonFieldType.NULL).description("region")
                    ),
                    responseFields(
                         fieldWithPath("success").type(JsonFieldType.NULL).description("success"),
                          fieldWithPath("message").type(JsonFieldType.STRING).description("message"),
                          fieldWithPath("code").type(JsonFieldType.STRING).description("code"),
                          fieldWithPath("errorData").type(JsonFieldType.NULL).description("errorData")
                    )
            ));
}
openapi: 3.0.1
info:
  title: test API
  description: test API
  version: 0.1.0
servers:
- url: https://localhost:8080
tags: []
paths:
  /auth/login:
    post:
      tags:
      - auth
      operationId: Hello World!Nice to meet you!
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/auth-login2050674939'
            examples:
              Hello World!:
                value: |-
                  {
                    "deviceToken" : "deviceToken",
                    "deviceType" : "aos",
                    "email" : "loginId",
                    "password" : "password",
                    "region" : "82"
                  }
              Nice to meet you!:
                value: |-
                  {
                    "deviceToken" : "deviceToken",
                    "deviceType" : "aos",
                    "email" : "loginId",
                    "password" : "password",
                    "region" : "82"
                  }
      responses:
        "200":
          description: "200"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/auth-login1551218249'
              examples:
                Hello World!:
                  value: |-
                    {
                      "success" : false,
                      "message" : "Invalid device token.",
                      "code" : 3003,
                      "errorData" : null
                    }
                Nice to meet you!:
                  value: |-
                    {
                      "success" : false,
                      "message" : "test user.",
                      "code" : 3017,
                      "errorData" : null
                    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant