javiergamarra / liferay-devcon-appointment

11 stars 19 forks source link

buildREST not work with multiple tags #2

Open sytolk opened 4 years ago

sytolk commented 4 years ago

If I use multiple tags - different tag: https://github.com/nhpatt/liferay-devcon-appointment/blob/master/appointments-impl/rest-openapi.yaml#L65 for different schema buildREST gradle task do not create classes for the new Tag and edit and delete operationId form my rest-openapi.yaml

javiergamarra commented 4 years ago

Have you tried with the latest version of REST Builder? 1.0.98?

sytolk commented 4 years ago

No I have restBuilder group: "com.liferay", name: "com.liferay.portal.tools.rest.builder", version: "1.0.23" If I have set REST Builder version to 1.0.98 its have exception:

freemarker.core._TemplateModelException: [... Exception message was already printed; see it above ...]
    at freemarker.ext.beans._MethodUtil.newInvocationTemplateModelException(_MethodUtil.java:289)
    at freemarker.ext.beans._MethodUtil.newInvocationTemplateModelException(_MethodUtil.java:252)
    at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:77)
    at freemarker.core.MethodCall._eval(MethodCall.java:65)
    at freemarker.core.Expression.eval(Expression.java:83)
    at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:100)
    at freemarker.core.DollarVariable.accept(DollarVariable.java:63)
    at freemarker.core.Environment.visit(Environment.java:366)
    at freemarker.core.IteratorBlock$IterationContext.executedNestedContentForCollOrSeqListing(IteratorBlock.java:317)
    at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:271)
    at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:242)
    at freemarker.core.Environment.visitIteratorBlock(Environment.java:642)
    at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:107)
    at freemarker.core.IteratorBlock.accept(IteratorBlock.java:93)
    at freemarker.core.Environment.visit(Environment.java:330)
    at freemarker.core.Environment.visit(Environment.java:336)
    at freemarker.core.Environment.process(Environment.java:309)
    at freemarker.template.Template.process(Template.java:384)
    at com.liferay.portal.tools.rest.builder.internal.freemarker.FreeMarker.processTemplate(FreeMarker.java:60)
    at com.liferay.portal.tools.rest.builder.internal.freemarker.util.FreeMarkerUtil.processTemplate(FreeMarkerUtil.java:32)
    at com.liferay.portal.tools.rest.builder.RESTBuilder._createGraphQLQueryFile(RESTBuilder.java:865)
    at com.liferay.portal.tools.rest.builder.RESTBuilder.build(RESTBuilder.java:218)
    at com.liferay.portal.tools.rest.builder.RESTBuilder.main(RESTBuilder.java:115)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1967)
    at com.liferay.portal.vulcan.yaml.graphql.GraphQLNamingUtil.getGraphQLPropertyName(GraphQLNamingUtil.java:48)
    at com.liferay.portal.tools.rest.builder.internal.freemarker.tool.FreeMarkerTool.getGraphQLPropertyName(FreeMarkerTool.java:313)
    at com.liferay.portal.tools.rest.builder.internal.freemarker.tool.FreeMarkerTool._getGraphQLBody(FreeMarkerTool.java:743)
    at com.liferay.portal.tools.rest.builder.internal.freemarker.tool.FreeMarkerTool.getGraphQLMethodJavadoc(FreeMarkerTool.java:274)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:1505)
    at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:72)

currently its have REST builder v.104 (with the same Gradle buildREST task exception) https://mvnrepository.com/artifact/com.liferay/com.liferay.portal.tools.rest.builder/1.0.104 but it's appears that every commit in builder is a new alpha version

javiergamarra commented 4 years ago

Every change in the code is a new version, can you paste your OpenAPI.yaml?

sytolk commented 4 years ago

This is my rest-openapi.yaml it works like that but its not very clean solution.. you can try to change tags: ["News"] -> tags: ["Categories"] or tags: ["Documents"]

components:
  schemas:
    Category:
      description: Contains Categories.
      properties:
        categoryId:
          description: The internal ID.
          format: int64
          type: integer
        adminRole:
          description: The adminRole.
          type: string
        editRole:
          description: The editRole.
          type: string
        companyId:
          description: The companyId.
          format: int64
          type: integer
        name:
          description: The Category name.
          type: string
        color:
          description: The Category color.
          type: string
        background_color:
          description: The Category background_color.
          type: string
      type: object
    Documents:
      description: Contains Documents.
      properties:
        documentId:
          description: The internal ID.
          format: int64
          type: integer
        newsId:
          $ref: "#/components/schemas/News"
        attachment_url:
          format: uri
          type: string
        companyId:
          format: int64
          type: integer
      type: object
    News:
      description: Contains News.
      properties:
        newsId:
          description: The internal ID.
          format: int64
          type: integer
        categoryId:
          $ref: "#/components/schemas/Category"
        companyId:
          format: int64
          type: integer
        title:
          type: string
        description:
          type: string
        date_from:
          format: int64
          type: integer
        date_to:
          format: int64
          type: integer
      type: object
openapi: 3.0.1
info:
  description: "API for accessing News details."
  license:
    name: "Apache 2.0"
    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
  title: "Headless News Api"
  version: v1.0
paths:
  "/categories":
    get:
      operationId: getCategoriesPage
      tags: ["News"]
      description: Retrieves the list of Categories. Results can be paginated, filtered, searched, and sorted.
      responses:
        200:
          description: ""
          content:
            application/json:
              schema:
                items:
                  $ref: "#/components/schemas/Category"
                type: array
            application/xml:
              schema:
                items:
                  $ref: "#/components/schemas/Category"
                type: array
  "/documents":
    post:
      operationId: postDocument
      tags: ["News"]
      description: Create a new Documents.
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Documents"
          application/xml:
            schema:
              $ref: "#/components/schemas/Documents"
      responses:
        200:
          description: ""
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Documents"
            application/xml:
              schema:
                $ref: "#/components/schemas/Documents"
  "/documents/{newsId}":
    get:
      operationId: getDocumentNews
      tags: ["News"]
      description: Retrieves the list of Documents via newsId.
      parameters:
        - name: newsId
          in: path
          required: true
          schema:
            type: string
      responses:
        200:
          description: ""
          content:
            application/json:
              schema:
                items:
                  $ref: "#/components/schemas/Documents"
                type: array
            application/xml:
              schema:
                items:
                  $ref: "#/components/schemas/Documents"
                type: array
  "/documents/all":
    get:
      operationId: getDocumentAllPage
      tags: ["News"]
      description: Retrieves the list of Documents.
      responses:
        200:
          description: ""
          content:
            application/json:
              schema:
                items:
                  $ref: "#/components/schemas/Documents"
                type: array
            application/xml:
              schema:
                items:
                  $ref: "#/components/schemas/Documents"
                type: array
  "/news/all":
    get:
      operationId: getNewsesAllPage
      tags: ["News"]
      description: Retrieves the list of News. Results can be paginated, filtered, searched, and sorted.
      responses:
        200:
          description: ""
          content:
            application/json:
              schema:
                items:
                  $ref: "#/components/schemas/News"
                type: array
            application/xml:
              schema:
                items:
                  $ref: "#/components/schemas/News"
                type: array
  "/news":
    get:
      operationId: getNewsPage
      tags: ["News"]
      description: Retrieves the list of News. Results can be paginated, filtered, searched, and sorted.
      parameters:
        - in: query
          name: filter
          schema:
            type: string
        - in: query
          name: page
          schema:
            type: integer
        - in: query
          name: pageSize
          schema:
            type: integer
        - in: query
          name: search
          schema:
            type: string
        - in: query
          name: sort
          schema:
            type: string
      responses:
        200:
          description: ""
          content:
            application/json:
              schema:
                items:
                  $ref: "#/components/schemas/News"
                type: array
            application/xml:
              schema:
                items:
                  $ref: "#/components/schemas/News"
                type: array
    post:
      operationId: postNews
      tags: ["News"]
      description: Create a new News.
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/News"
          application/xml:
            schema:
              $ref: "#/components/schemas/News"
      responses:
        200:
          description: ""
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/News"
            application/xml:
              schema:
                $ref: "#/components/schemas/News"
  "/news/{newsId}":
    get:
      operationId: getNews
      tags: ["News"]
      description: Retrieves the News via its ID.
      parameters:
        - name: newsId
          in: path
          required: true
          schema:
            type: string
      responses:
        200:
          description: ""
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/News"
            application/xml:
              schema:
                $ref: "#/components/schemas/News"
    put:
      operationId: putNews
      tags: ["News"]
      description: Replaces the News with the information sent in the request body. Any missing fields are deleted, unless they are required.
      parameters:
        - name: newsId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/News"
          application/xml:
            schema:
              $ref: "#/components/schemas/News"
      responses:
        200:
          description: Default Response
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/News"
            application/xml:
              schema:
                $ref: "#/components/schemas/News"
    patch:
      operationId: patchNews
      tags: ["News"]
      description: Replaces the News with the information sent in the request body. Any missing fields are deleted, unless they are required.
      parameters:
        - name: newsId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/News"
          application/xml:
            schema:
              $ref: "#/components/schemas/News"
      responses:
        200:
          description: ""
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/News"
            application/xml:
              schema:
                $ref: "#/components/schemas/News"
    delete:
      operationId: deleteNews
      tags: ["News"]
      description: Deletes the News and returns a 204 if the operation succeeds.
      parameters:
        - name: newsId
          in: path
          required: true
          schema:
            type: string
      responses:
        200:
          description: ""
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/News"
            application/xml:
              schema:
                $ref: "#/components/schemas/News"