openapi: 3.0.1
info:
  title: Printer Service API
  description: Generates documents based on XDocReport or JasperReport by merging a template and a data model.
  version: 2.0.0

servers:
  - url: http://printer/v2

tags:
  - name: Printer
    description: The printer resource

paths:
  '/print/xdoc':
    post:
      tags:
        - Printer
      summary: Produces a document (odt, docx, doc, pdf) by merging the template and data provided within the XdocPrintMessage
      operationId: xdocPrint
      requestBody:
        description: A XdocPrintMessage
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/XdocPrintMessage'
      responses:
        '200':
          description: Document has been successfully generated
          content:
            application/pdf:
              schema:
                type: string
                format: byte
            'application/vnd.oasis.opendocument.text':
              schema:
                type: string
                format: byte
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
              schema:
                type: string
                format: byte
            'application/msword':
              schema:
                type: string
                format: byte
        '400':
          description: Bad request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Template not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  '/print/freemarker':
    post:
      tags:
      - Printer
      summary: Produces a plain text document by merging the freemarker template and data provided within the FreemarkerPrintMessage
      operationId: freemarkerPrint
      requestBody:
        description: A FreemarkerPrintMessage
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FreemarkerPrintMessage'
      responses:
        '200':
          description: Document has been successfully generated
          content:
            text/plain:
              schema:
                type: string
                format: byte
        '400':
          description: Bad request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Template not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  '/print/jasper':
    post:
      tags:
      - Printer
      summary: Produces a document (docx, odt, pdf) by merging the template and data provided within the JasperPrintMessage
      operationId: jasperPrint
      requestBody:
        description: A JasperPrintMessage
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/JasperPrintMessage'
      responses:
        '200':
          description: Document has been successfully generated
          content:
            application/pdf:
              schema:
                type: string
                format: byte
            'application/vnd.oasis.opendocument.text':
              schema:
                type: string
                format: byte
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
              schema:
                type: string
                format: byte
            'application/msword':
              schema:
                type: string
                format: byte
        '400':
          description: Bad request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Template not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

components:
  schemas:
    Error:
      type: object
      properties:
        timestamp:
          type: string
          format: date
        status:
          type: int
        error:
          type: string
        message:
          type: string
        path:
          type: string
    XdocPrintMessage:
      type: object
      required:
        - templateUrl
        - data
      properties:
        templateUrl:
          type: string
          description: URL of the template used for the generation. Can be either absolute or relative (to a configured base url).
        convert:
          type: boolean
          description: When true the generated document is converted to pdf.
        data:
          type: object
          description: The data model to merge.
        fieldsMetadata:
          type: array
          description: Metadata about how to manage data model fields.
          items:
            $ref: '#/components/schemas/FieldMetadata'
    #            oneOf:
    #              - $ref: '#/components/schemas/FieldMetadata'
    #              - $ref: '#/components/schemas/ImageFieldMetadata'
    #              - $ref: '#/components/schemas/TextStylingFieldMetadata'
    FieldMetadata:
      type: object
      required:
        - fieldName
      properties:
        fieldName:
          type: string
          description: The model field name
        listType:
          type: boolean
          description: Set to true if field is a list
      description: visit this [link](https://github.com/opensagres/xdocreport/wiki/DocxReportingJavaMainListFieldInTable) and [this](https://github.com/opensagres/xdocreport/wiki/DocxReportingJavaMainListFieldAdvancedTable)
    ImageFieldMetadata:
      allOf:
        - $ref: '#/components/schemas/FieldMetadata'
        - type: object
          required:
            - nullImageBehaviour
          properties:
            useImageSize:
              type: boolean
            nullImageBehaviour:
              type: string
              enum: [ThrowsError, RemoveImageTemplate, KeepImageTemplate]
      description: visit this [link](https://github.com/opensagres/xdocreport/wiki/DocxReportingJavaMainDynamicImage)
    TextStylingFieldMetadata:
      allOf:
        - $ref: '#/components/schemas/FieldMetadata'
        - type: object
          required:
            - syntaxKind
          properties:
            syntaxWithDirective:
              type: boolean
              description: true if the field value contains FreeMarker directives
            syntaxKind:
              type: string
              enum: [NoEscape, Html, GWiki, MediaWiki, MarkDown]
      description: visit this [link](https://github.com/opensagres/xdocreport/wiki/DocxReportingJavaMainTextStyling)
    JasperExporterConfigParams:
      type: string
      description: list of parameters used to configure the jasper exporter (pdf, docx, csv).
      enum:
        - "exporter.pdf.report.forceSvgShapes"
        - "exporter.pdf.report.sizePageToContent"
        - "exporter.pdf.report.forceLineBreakPolicy"
        - "exporter.pdf.export.allowedPermissionsHint"
        - "exporter.pdf.export.deniedPermissionsHint"
        - "exporter.pdf.export.metadataCreator"
        - "exporter.pdf.export.displayMetadataTitle"
        - "exporter.all.export.metadataTitle"
        - "exporter.all.export.metadataAuthor"
        - "exporter.all.export.metadataSubject"
        - "exporter.all.export.metadataKeywords"
        - "exporter.docx.export.metadataApplication"
        - "exporter.docx.export.embedFonts"
        - "exporter.csv.report.writeHeader"
        - "exporter.csv.export.fieldEnclosure"
        - "exporter.csv.export.forceFieldEnclosure"
        - "exporter.csv.export.recordDelimiter"
        - "exporter.csv.export.fieldDelimiter"
    JasperPrintMessage:
      type: object
      required:
      - templateUrl
      - data
      properties:
        templateUrl:
          type: string
          description: Name of the template used for the generation (name of the provided zip file).
        exportType:
          type: string
          enum: [PDF, ODT, DOCX, CSV]
          default: PDF
          description: Type of the export.
        data:
          type: object
          description: The data model to merge.
        parameters:
          type: object
          additionalProperties:
            type: object
          description: "map of additional parameters that may be referenced within the template.
          Furthermore the jasper service handles a defined list of parameters (JasperExporterConfigParams) used to configure the jasper exporter (see [The Jasper Exporter Configuration](https://github.com/PC-Scol/printer#the-jasper-exporter-configuration))."
    FreemarkerPrintMessage:
      type: object
      required:
      - templateName
      - data
      properties:
        templateName:
          type: string
          description: Name of the template used for the generation.
        data:
          type: object
          description: The data model to merge.
