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

Improve OpenAPI support in Swagger .json and .yaml #76

Open
belyaev-andrey opened this issue Nov 8, 2019 · 2 comments
Open

Improve OpenAPI support in Swagger .json and .yaml #76

belyaev-andrey opened this issue Nov 8, 2019 · 2 comments
Assignees
Labels
type: enhancement New feature or request

Comments

@belyaev-andrey
Copy link

We need to infer parameter types and add those types to the "definitions" section in

http://localhost:8080/app/rest/v2/docs/swagger.yaml
http://localhost:8080/app/rest/v2/docs/swaggerDetailed.yaml

files.

For example, for the project https://github.com/cuba-platform/sample-session-planner we can create the following descriptor for REST service publication:

<?xml version="1.0" encoding="UTF-8"?>
<services xmlns="http://schemas.haulmont.com/cuba/rest-services-v2.xsd">
    <service name="sessionplanner_SessionService">
        <method name="rescheduleSession" anonymousAllowed="true">
            <param name="newStartDate"/>
            <param name="session"/>
        </method>
    </service>
</services>

It is not easy to add a proper type for the session parameter (it is an entity), therefore, we get the following swagger descriptior:

    post:
      produces:
      - "application/json"
      parameters:
      - originalRef: "#/parameters/sessionplanner_SessionService_rescheduleSession_paramsObject_POST"
        $ref: "#/parameters/sessionplanner_SessionService_rescheduleSession_paramsObject_POST"

  sessionplanner_SessionService_rescheduleSession_paramsObject_POST:
    in: "body"
    name: "paramsObject"
    required: true
    schema:
      properties:
        newStartDate:
          type: "string"
        session:
          type: "string"

But session is not string, its structure is:

public class Session extends StandardEntity {
    protected String topic;
    protected Date startDate;
    protected Date endDate;
    protected Speaker speaker;
}

And this prevents us from generating the proper client application based on the swagger descriptor. Service method parameter types should be properly supported.

@belyaev-andrey belyaev-andrey added the type: enhancement New feature or request label Nov 8, 2019
@knstvk
Copy link
Member

knstvk commented Nov 11, 2019

What if you specify the parameter type in rest-services.xml as described here? Will the OpenAPI contain the type?

@belyaev-andrey
Copy link
Author

In the documentation we describe only "simple" types, but not ones that might require complex serialization/deserialization. For the description:

        <method name="rescheduleSession" anonymousAllowed="true">
            <param name="session" type="com.company.sessionplanner.entity.Session"/>
            <param name="newStartDate" type="java.util.Date"/>
        </method>

It generates the following description for POST:

      parameters:
      - $ref: "#/parameters/sessionplanner_SessionService_rescheduleSession_paramsObject_POST"
        originalRef: "#/parameters/sessionplanner_SessionService_rescheduleSession_paramsObject_POST"

  sessionplanner_SessionService_rescheduleSession_paramsObject_POST:
    in: "body"
    name: "paramsObject"
    required: true
    schema:
      properties:
        newStartDate:
          type: "string"
          format: "date"
          example: "2005-14-10T13:17:42.16Z"
        session:
          type: "object"
          description: "sessionplanner_Session"

And for GET:

      parameters:
      - $ref: "#/parameters/sessionplanner_SessionService_rescheduleSession_session_GET"
        originalRef: "#/parameters/sessionplanner_SessionService_rescheduleSession_session_GET"
      - $ref: "#/parameters/sessionplanner_SessionService_rescheduleSession_newStartDate_GET"
        originalRef: "#/parameters/sessionplanner_SessionService_rescheduleSession_newStartDate_GET"

  sessionplanner_SessionService_rescheduleSession_newStartDate_GET:
    name: "newStartDate"
    in: "query"
    required: true
    type: "string"
  sessionplanner_SessionService_rescheduleSession_session_GET:
    name: "session"
    in: "query"
    required: true
    type: "string"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants