OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.74k stars 6.56k forks source link

How can i integrate my access token generation and refreshing code into client auto generated code. #776

Open pgnaleen opened 6 years ago

pgnaleen commented 6 years ago
Description

there is a API gateway middle of the Rest Service and my client. So i need to connect to that API using access token. So that access token generation and refreshing part i need to add into auto generated client code. Also i need proper documentation for learn how to write mustache templates. Thanks in advance for your support.

openapi-generator version

3

pgnaleen commented 6 years ago

i added template directory like following but not working in eclipse

4.0.0 org.openapitools sample-project jar 1.0-SNAPSHOT sample-project http://maven.apache.org org.openapitools openapi-generator-maven-plugin 3.1.2 generate ${project.basedir}/swagger.yaml ${project.basedir}/templates java joda jersey2 org.apache.maven.plugins maven-compiler-plugin 3.6.1 1.7 1.7 io.swagger swagger-annotations ${swagger-annotations-version} org.glassfish.jersey.core jersey-client ${jersey-version} org.glassfish.jersey.media jersey-media-multipart ${jersey-version} org.glassfish.jersey.media jersey-media-json-jackson ${jersey-version} com.fasterxml.jackson.jaxrs jackson-jaxrs-base ${jackson-version} com.fasterxml.jackson.core jackson-core ${jackson-version} com.fasterxml.jackson.core jackson-annotations ${jackson-version} com.fasterxml.jackson.core jackson-databind ${jackson-version} com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider ${jackson-version} com.fasterxml.jackson.datatype jackson-datatype-joda ${jackson-version} joda-time joda-time ${jodatime-version} com.brsanthu migbase64 2.2 1.5.8 2.27 2.8.9 2.7 1.0.0 4.8.1
pgnaleen commented 6 years ago
${project.basedir}/swagger.yaml ${project.basedir}/templates this not working so added folllwing still not working ${project.basedir}/swagger.yaml java ${project.basedir}/templates joda
pgnaleen commented 6 years ago

anyone please help me.

wing328 commented 6 years ago

<templateDirectory> should be the at same level as <generatorName>

<configOptions> refers to generator-specified options

pgnaleen commented 6 years ago

this is pom again

generate ${project.basedir}/swagger.yaml java ${project.basedir}/templates ture true true ture true model auth joda jersey2

still not working

OAuth.mustache file like below.

{{>licenseInfo}}

package {{invokerPackage}}.auth;

import {{invokerPackage}}.Pair;

import java.util.Map; import java.util.List;

{{>generatedAnnotation}} public class OAuth implements Authentication { private String accessToken;

public String getAccessToken() { return accessToken123; }

public void setAccessToken(String accessToken) { this.accessToken = accessToken; }

@Override public void applyToParams(List queryParams, Map<String, String> headerParams) { if (accessToken != null) { headerParams.put("Authorization", "Bearer " + accessToken); } } }

pgnaleen commented 6 years ago

hello i created java custom generator. please send me how can i use that in pom.xml to generate apiClient

this is command i used. java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar meta \ -o out/generators/my-codegen -n my-codegen -p com.my.company.codegen

then copied all java templates. then mvn package custom java-generator created but please kind enough to send me suitable pom to add this generator and generate apiClient. I think templateDirectory no need to add.