OpenAPITools / OpenAPITools/openapi-generator

[BUG][SPRING] Incorrect handling of `format: byte` in query strings

Open
#22,898 7 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?
  • 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 generating a spring-cloud implementation with a query string parameter with format: byte the parameter is not decoded as base64 (as required by the spec).

openapi-generator version

1.8.0

OpenAPI declaration file content or url
openapi: '3.0.3'
info:
  title: Test API
  version: '1.0'
servers:
  - url: https://api.server.test/v1
paths:
  /test:
    get:
      parameters:
        - name: data
          in: query
          schema:
            type: string
            format: byte
      responses:
        '200':
          description: OK
Generation Details

pom.xml:

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<executions>
	<execution>
		<id>generate-api</id>
		<goals>
			<goal>generate</goal>
		</goals>
		<configuration>
			<inputSpec>
				${project.basedir}/src/main/resources/testapi.yaml
			</inputSpec>
			<generatorName>spring</generatorName>
			<library>spring-boot</library>
			<generateSupportingFiles>false</generateSupportingFiles>
			<skipOperationExample>true</skipOperationExample>
			<configOptions>
				<delegatePattern>false</delegatePattern>
				<useSpringBoot3>true</useSpringBoot3>
				<interfaceOnly>true</interfaceOnly>
			</configOptions>
		</configuration>
	</execution>
</executions>
</plugin>
Steps to reproduce

Generate code from the spec above. Implement the endpoint:

@RestController
public class TestController implements TestApi {

    @Override
    public ResponseEntity<Void> testGet(byte[] data) {
        StringBuilder hexString = new StringBuilder();
        for (byte b : data) {
            hexString.append(String.format("%02x", b));
        }
        System.out.println(hexString.toString());
        return ResponseEntity.ok().build();
    }
}

Note: The paramter is a byte[] as expected.

Send a sample request:

curl http://localhost:8080/test?data=abc

Actual output: 616263 (ascii encoding of "abc")
Expected output: 69b7 (base64 decoding of "abc")

Related issues/PRs
Suggest a fix

I don't know Spring very well, maybe there is some kind of annotation that can be used to make Spring decode the value correctly? Alternatively the generator should emit an error that format: byte is not supported.

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

Start with the generated Spring controller binding for the data query parameter and the spring-boot generation settings shown in the issue. Reproduce the curl request with the supplied OpenAPI declaration, then determine whether the generated endpoint decodes format: byte as base64 or reports the format as unsupported; done means the behavior matches the specification or is explicitly rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.