OpenAPITools / OpenAPITools/openapi-generator

[BUG][AVRO] String of type byte is not well converted to Avro Bytes format

Open
#20,567 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When trying to generate an Avro schema from an open api spec that contains a type string with format byte, the corresponding generated type is "mode.Bytes" instead of "bytes".

    {
      "name": "certi",
      "type": ["null", "model.Bytes"],
      "doc": "Base64 encoded certificate",
      "default": null
    }

instead of

    {
      "name": "certi",
      "type": ["null", "bytes"],
      "doc": "Base64 encoded certificate",
      "default": null
    }
openapi-generator version

openapi-generator-cli 7.10.0
commit : 12dfe8f

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Sample API
  description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
  version: 0.1.9

servers:
  - url: http://api.example.com/v1
    description: Optional server description, e.g. Main (production) server
  - url: http://staging-api.example.com
    description: Optional server description, e.g. Internal staging server for testing

paths:
  /users:
    get:
      summary: Returns a list of users.
      description: Optional extended description in CommonMark or HTML.
      responses:
        "200": # status code
          description: A JSON array of user names
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
components:
  schemas:
    Alert:
      type: object
      properties:
        certi:
          description: Base64 encoded certificate
          type: string
          format: byte
Steps to reproduce
openapi-generator-cli generate -g avro-schema -i resources/test/openapi-spec.yaml -o test
Related issues/PRs
Suggest a fix

I'd be happy to try to fix it, but I'm fairly new to mustach template within openapi generator.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the shown avro-schema generation command with resources/test/openapi-spec.yaml and compare the generated schema for Alert.certi. Start by tracing the Avro-schema generator's Mustache template or mapping that produces model.Bytes. Done means a string with format byte generates Avro type bytes, with coverage for this reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.