Skip to content

Commit 4c1cffe

Browse files
authored
Merge branch 'OpenAPITools:master' into master
2 parents c9ad1c7 + 4f9f14a commit 4c1cffe

File tree

65 files changed

+5003
-1799
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+5003
-1799
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Samples Crystal clients
2+
3+
on:
4+
push:
5+
paths:
6+
- samples/client/petstore/crystal/**
7+
pull_request:
8+
paths:
9+
- samples/client/petstore/crystal/**
10+
jobs:
11+
build:
12+
name: Build Crystal projects
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
sample:
18+
# clients
19+
- samples/client/petstore/crystal/
20+
services:
21+
petstore-api:
22+
image: swaggerapi/petstore
23+
ports:
24+
- 80:8080
25+
env:
26+
SWAGGER_HOST: http://petstore.swagger.io
27+
SWAGGER_BASE_PATH: /v2
28+
steps:
29+
- uses: actions/checkout@v5
30+
- name: Install Crystal
31+
uses: crystal-lang/install-crystal@v1
32+
- name: Shards Install
33+
run: shards install
34+
working-directory: ${{ matrix.sample }}
35+
- name: Run tests
36+
run: crystal spec
37+
working-directory: ${{ matrix.sample }}

.github/workflows/samples-swift5.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
runs-on: ${{ matrix.os }}
3636
steps:
3737
- uses: actions/checkout@v5
38-
- uses: swift-actions/setup-swift@v2
38+
- uses: swift-actions/setup-swift@v3
3939
if: ${{ matrix.os == 'ubuntu-latest' }}
4040
with:
4141
swift-version: '5'

bin/configs/crystal.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ additionalProperties:
66
shardVersion: 1.0.0
77
moduleName: Petstore
88
shardName: petstore
9+
#paramsEncoder: Crest::EnumeratedFlatParamsEncoder
910
strictSpecBehavior: false
1011
modelNameMappings:
1112
PropertyNameMapping: AnotherPropertyNameMapping

docs/generators/crystal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2525
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
2626
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
2727
|moduleName|module name (e.g. TwitterClient| |OpenAPIClient|
28+
|paramsEncoder|params_encoder setting (e.g. Crest::NestedParamsEncoder, Crest::EnumeratedFlatParamsEncoder, Crest::ZeroEnumeratedFlatParamsEncoder| |Crest::NestedParamsEncoder|
2829
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
2930
|shardAuthor|shard author (only one is supported).| |null|
3031
|shardAuthorEmail|shard author email (only one is supported).| |null|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public CppPistacheServerCodegen() {
191191
private void setupSupportingFiles() {
192192
supportingFiles.clear();
193193
supportingFiles.add(new SupportingFile("api-base-header.mustache", "api", "ApiBase.h"));
194+
supportingFiles.add(new SupportingFile("api-base-source.mustache", "api", "ApiBase.cpp"));
194195
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
195196
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
196197
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CrystalClientCodegen.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class CrystalClientCodegen extends DefaultCodegen {
5757
@Setter protected String shardDescription = "This shard maps to a REST API";
5858
@Setter protected String shardAuthor = "";
5959
@Setter protected String shardAuthorEmail = "";
60+
@Setter protected String paramsEncoder = "Crest::NestedParamsEncoder";
6061
protected String apiDocPath = "docs/";
6162
protected String modelDocPath = "docs/";
6263
protected List<String> primitiveTypes = new ArrayList<String>();
@@ -70,6 +71,7 @@ public class CrystalClientCodegen extends DefaultCodegen {
7071
public static final String SHARD_DESCRIPTION = "shardDescription";
7172
public static final String SHARD_AUTHOR = "shardAuthor";
7273
public static final String SHARD_AUTHOR_EMAIL = "shardAuthorEmail";
74+
public static final String PARAMS_ENCODER = "paramsEncoder";
7375

7476
public CrystalClientCodegen() {
7577
super();
@@ -197,15 +199,18 @@ public CrystalClientCodegen() {
197199

198200
cliOptions.add(new CliOption(SHARD_HOMEPAGE, "shard homepage.").defaultValue("http://org.openapitools"));
199201

200-
cliOptions.add(
201-
new CliOption(SHARD_DESCRIPTION, "shard description.").defaultValue("This shard maps to a REST API"));
202+
cliOptions.add(new CliOption(SHARD_DESCRIPTION, "shard description.").defaultValue("This shard maps to a REST API"));
202203

203204
cliOptions.add(new CliOption(SHARD_AUTHOR, "shard author (only one is supported)."));
204205

205206
cliOptions.add(new CliOption(SHARD_AUTHOR_EMAIL, "shard author email (only one is supported)."));
206207

207208
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP,
208209
CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC).defaultValue(Boolean.TRUE.toString()));
210+
211+
cliOptions.add(new CliOption(PARAMS_ENCODER,
212+
"params_encoder setting (e.g. Crest::NestedParamsEncoder, Crest::EnumeratedFlatParamsEncoder, Crest::ZeroEnumeratedFlatParamsEncoder").
213+
defaultValue("Crest::NestedParamsEncoder"));
209214
}
210215

211216
@Override
@@ -260,6 +265,12 @@ public void processOpts() {
260265
setShardAuthorEmail((String) additionalProperties.get(SHARD_AUTHOR_EMAIL));
261266
}
262267

268+
if (additionalProperties.containsKey(PARAMS_ENCODER)) {
269+
setParamsEncoder((String) additionalProperties.get(PARAMS_ENCODER));
270+
} else {
271+
additionalProperties.put(PARAMS_ENCODER, paramsEncoder);
272+
}
273+
263274
// make api and model doc path available in mustache template
264275
additionalProperties.put("apiDocPath", apiDocPath);
265276
additionalProperties.put("modelDocPath", modelDocPath);

modules/openapi-generator/src/main/resources/cpp-oatpp-server/main-api-server.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public:
2222
* Create ConnectionProvider component which listens on the port
2323
*/
2424
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, serverConnectionProvider)([] {
25-
return oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", {{serverPort}}{{^serverPort}}8080{{/serverPort}}, oatpp::network::Address::IP_4});
25+
return oatpp::network::tcp::server::ConnectionProvider::createShared({"0.0.0.0", {{serverPort}}{{^serverPort}}8080{{/serverPort}}, oatpp::network::Address::IP_4});
2626
}());
2727

2828
/**

modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,47 @@
1414
namespace {{apiNamespace}}
1515
{
1616
17+
18+
{{#authMethods}}{{#isBasicBasic}}
19+
typedef struct
20+
{
21+
std::string user;
22+
std::string password;
23+
std::unique_ptr<void, std::function<void(void*)>> userdata;
24+
} HttpBasicCredentials;
25+
26+
typedef std::function<bool(HttpBasicCredentials &)> BasicCredentialsAuthenticator;
27+
{{/isBasicBasic}}
28+
29+
{{#isBasicBearer}}
30+
typedef struct
31+
{
32+
std::string token;
33+
std::unique_ptr<void, std::function<void(void*)>> userdata;
34+
} HttpBearerToken;
35+
36+
typedef std::function<bool(HttpBearerToken &)> BearerTokenAuthenticator;
37+
{{/isBasicBearer}}
38+
{{/authMethods}}
39+
40+
41+
1742
class ApiBase {
1843
public:
19-
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr) {};
44+
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr);
2045
virtual ~ApiBase() = default;
2146
virtual void init() = 0;
2247
48+
{{#authMethods}}{{#isBasicBasic}}void setBasicCredentialsAuthenticator( const BasicCredentialsAuthenticator &newBasicCredentialsAuthenticator);{{/isBasicBasic}}{{/authMethods}}
49+
{{#authMethods}}{{#isBasicBearer}}void setBearerTokenAuthenticator( const BearerTokenAuthenticator &newbearerTokenAuthenticator);{{/isBasicBearer}}{{/authMethods}}
50+
51+
2352
protected:
2453
const std::shared_ptr<Pistache::Rest::Router> router;
54+
{{#authMethods}}{{#isBasicBasic}}std::optional<BasicCredentialsAuthenticator> basicCredentialsAuthenticator;{{/isBasicBasic}}{{/authMethods}}
55+
{{#authMethods}}{{#isBasicBearer}}std::optional<BearerTokenAuthenticator> bearerTokenAuthenticator;{{/isBasicBearer}}{{/authMethods}}
56+
57+
2558
};
2659

2760
} // namespace {{apiNamespace}}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{{>licenseInfo}}
2+
#include "ApiBase.h"
3+
4+
namespace {{apiNamespace}}
5+
{
6+
7+
ApiBase::ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr)
8+
{
9+
}
10+
11+
{{#authMethods}}{{#isBasicBasic}}
12+
void ApiBase::setBasicCredentialsAuthenticator( const BasicCredentialsAuthenticator &newBasicCredentialsAuthenticator)
13+
{
14+
basicCredentialsAuthenticator = newBasicCredentialsAuthenticator;
15+
}
16+
{{/isBasicBasic}}
17+
{{#isBasicBearer}}
18+
void ApiBase::setBearerTokenAuthenticator( const BearerTokenAuthenticator &newbearerTokenAuthenticator)
19+
{
20+
bearerTokenAuthenticator = newbearerTokenAuthenticator;
21+
}
22+
{{/isBasicBearer}}
23+
{{/authMethods}}
24+
25+
} // Namespace {{apiNamespace}}

modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private:
7979
{{#allParams}}
8080
/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
8181
{{/allParams}}
82-
virtual void {{operationIdSnakeCase}}({{#allParams}}const {{#isModel}}{{^isOptional}}{{modelNamespace}}::{{/isOptional}}{{/isModel}}{{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) = 0;
82+
virtual void {{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const HttpBasicCredentials &credentials, {{/isBasicBasic}}{{#isBasicBearer}}const HttpBearerToken &accessToken, {{/isBasicBearer}}{{/authMethods}} {{#allParams}}const {{#isModel}}{{^isOptional}}{{modelNamespace}}::{{/isOptional}}{{/isModel}}{{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) = 0;
8383
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}
8484
{{^vendorExtensions.x-codegen-pistache-is-parsing-supported}}
8585
virtual void {{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0;

0 commit comments

Comments
 (0)