OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] scheme default to HTTP instead of HTTPS

Open
#11,507 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

Description

I generate a client using java generator with a OpenAPI declaration that is available through a https url. No "scheme" is available in this declaration but the documentation specify :

f the schemes is not included, the default scheme to be used is the one used to access the Swagger definition itself.

However, I get the following warning and the client is mapped to the wrong endpoint.

[WARNING] 'scheme' not defined in the spec (2.0). Default to [http] for server URL [http://scanr-api.enseignementsup-recherche.gouv.fr/api]

openapi-generator version

5.4.0

OpenAPI declaration file content or url

https://scanr-api.enseignementsup-recherche.gouv.fr/api/v2/api-docs

Steps to reproduce

mvn clean complie

The pom.xml that I use

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>apiclient</artifactId>
        <groupId>fr.theialand.insitu</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>apiclient-scanr</artifactId>

    <description>ScanR client, returns Structures of research entities</description>

    <dependencies>
        <dependency>
            <groupId>fr.theialand.insitu</groupId>
            <artifactId>apiclient-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <!-- Needed by the code generated by codegen -->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>1.6.2</version>
        </dependency>

        <!-- Needed by the generator > 4.1.0 for @Nullable unofficial annotations
 issue : https://github.com/OpenAPITools/openapi-generator/issues/7177 -->
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <version>3.0.2</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <!-- Now we can generate the spring REST client, based on restTemplate -->
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>4.3.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>https://scanr-api.enseignementsup-recherche.gouv.fr/api/v2/api-docs</inputSpec>
<!--                            <inputSpec>${project.basedir}/src/main/resources/api-docs.json</inputSpec>-->
                            <generatorName>java</generatorName>
                            <skipValidateSpec>false</skipValidateSpec>

                            <configOptions>
                                <java8>true</java8>
                                <openApiNullable>false</openApiNullable>

                                <dateLibrary>legacy</dateLibrary> <!-- java.time new lib -->
                                <library>resttemplate</library> <!-- Spring http client -->
                                <serializationLibrary>jackson</serializationLibrary>
                                <sourceFolder>src/main/java</sourceFolder>
                            </configOptions>


                            <modelPackage>${project.groupId}.dataportal.api.scanr.model</modelPackage>
                            <apiPackage>${project.groupId}.dataportal.api.scanr.api</apiPackage>
                            <invokerPackage>${project.groupId}.dataportal.api.scanr.handler</invokerPackage>
                            <generateSupportingFiles>true</generateSupportingFiles>

                            <!-- other stuff generated by the codegen is buggy as sh*t , no need-->
                            <generateModelTests>false</generateModelTests>
                            <generateModelDocumentation>false</generateModelDocumentation>
                            <generateApiTests>false</generateApiTests>
                            <generateApiDocumentation>false</generateApiDocumentation>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

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 by running the openapi-generator Maven plugin with the supplied OpenAPI 2.0 URL and inspect where the Java generator handles a missing scheme. Compare the warning and generated endpoint with the declaration's HTTPS source URL. Done means generation defaults to the documented scheme behavior instead of mapping the client to HTTP.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.