Skip to content

Commit 4290b30

Browse files
committed
docker
1 parent 2f22e4a commit 4290b30

16 files changed

Lines changed: 381 additions & 144 deletions

File tree

.github/workflows/codegen-ci.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Codegen CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [main]
7+
paths:
8+
- 'codegen/**'
9+
- '.github/workflows/codegen-ci.yml'
10+
pull_request:
11+
paths:
12+
- 'codegen/**'
13+
- '.github/workflows/codegen-ci.yml'
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
17+
cancel-in-progress: true
18+
19+
env:
20+
CARGO_TERM_COLOR: always
21+
22+
jobs:
23+
formatting:
24+
name: Formatting
25+
runs-on: ubuntu-24.04
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: dtolnay/rust-toolchain@stable
30+
with:
31+
components: rustfmt
32+
- run: cargo fmt --check
33+
working-directory: codegen
34+
35+
clippy:
36+
name: Clippy
37+
runs-on: ubuntu-24.04
38+
39+
steps:
40+
- uses: actions/checkout@v4
41+
- uses: dtolnay/rust-toolchain@stable
42+
with:
43+
components: clippy
44+
- uses: Swatinem/rust-cache@v2
45+
with:
46+
workspaces: "codegen -> target"
47+
save-if: ${{ github.ref == 'refs/heads/main' }}
48+
prefix-key: "codegen"
49+
- run: cargo clippy -- -D warnings
50+
working-directory: codegen
51+
52+
typos:
53+
name: Typos
54+
runs-on: ubuntu-24.04
55+
56+
steps:
57+
- uses: actions/checkout@v4
58+
- uses: crate-ci/typos@v1.29.3
59+
with:
60+
files: codegen/
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: Codegen Docker Image
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [main]
7+
paths:
8+
- 'codegen/**'
9+
- '.github/workflows/codegen-docker.yml'
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
REGISTRY_IMAGE: ghcr.io/meteroid-oss/openapi-codegen
14+
15+
jobs:
16+
build:
17+
permissions:
18+
contents: read
19+
packages: write
20+
strategy:
21+
matrix:
22+
platform:
23+
- runner: ubuntu-24.04
24+
name: amd64
25+
build-args: |
26+
BIOME_DL_LINK=https://github.com/biomejs/biome/releases/download/%40biomejs%2Fbiome%402.1.4/biome-linux-x64-musl
27+
BIOME_SHA256=6d6bd2213cffab0d68d741c0be466bcd21cd6f5eca1e0e5aac2a991bf9f17cf2
28+
JAVAFMT_DL_LINK=https://repo1.maven.org/maven2/com/palantir/javaformat/palantir-java-format-native/2.75.0/palantir-java-format-native-2.75.0-nativeImage-linux-glibc_x86-64.bin
29+
JAVAFMT_SHA256=9d8c9e65cff44bb847d16b4db2ccbd6dacbe32611eaf2587748013eda931cdac
30+
- runner: ubuntu-24.04-arm
31+
name: arm64
32+
build-args: |
33+
BIOME_DL_LINK=https://github.com/biomejs/biome/releases/download/%40biomejs%2Fbiome%402.1.4/biome-linux-arm64-musl
34+
BIOME_SHA256=ffa05ea6ec0e73072e46301a692eb9413d5b683366e86ab7243414ae944f4ec4
35+
JAVAFMT_DL_LINK=https://repo1.maven.org/maven2/com/palantir/javaformat/palantir-java-format-native/2.75.0/palantir-java-format-native-2.75.0-nativeImage-linux-glibc_aarch64.bin
36+
JAVAFMT_SHA256=371e226632a5c455f017fe2ce2a614abe8cf81c743b4c27fb998373b790c2a3b
37+
name: Build and publish ${{ matrix.platform.name }} docker image
38+
if: github.ref == 'refs/heads/main'
39+
runs-on: "${{ matrix.platform.runner }}"
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Login to ghcr
44+
uses: docker/login-action@v3
45+
with:
46+
registry: ghcr.io
47+
username: ${{ github.actor }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v3
52+
53+
- name: Build and push by digest
54+
id: build
55+
uses: docker/build-push-action@v6
56+
with:
57+
tags: ${{ env.REGISTRY_IMAGE }}
58+
build-args: ${{ matrix.platform.build-args }}
59+
context: codegen
60+
file: codegen/Dockerfile
61+
cache-from: type=gha
62+
cache-to: type=gha,mode=max
63+
platforms: linux/${{ matrix.platform.name }}
64+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
65+
66+
- name: Export digest
67+
run: |
68+
mkdir -p ${{ runner.temp }}/digests
69+
digest="${{ steps.build.outputs.digest }}"
70+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
71+
72+
- name: Upload digest
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: digests-${{ matrix.platform.name }}
76+
path: ${{ runner.temp }}/digests/*
77+
if-no-files-found: error
78+
retention-days: 1
79+
80+
publish-merged-manifest:
81+
permissions:
82+
contents: read
83+
packages: write
84+
if: github.ref == 'refs/heads/main'
85+
runs-on: ubuntu-24.04
86+
needs:
87+
- build
88+
steps:
89+
- uses: actions/checkout@v4
90+
with:
91+
fetch-depth: 0
92+
93+
- name: Download digests
94+
uses: actions/download-artifact@v4
95+
with:
96+
path: ${{ runner.temp }}/digests
97+
pattern: digests-*
98+
merge-multiple: true
99+
100+
- name: Login to ghcr
101+
uses: docker/login-action@v3
102+
with:
103+
registry: ghcr.io
104+
username: ${{ github.actor }}
105+
password: ${{ secrets.GITHUB_TOKEN }}
106+
107+
- name: Set up Docker Buildx
108+
uses: docker/setup-buildx-action@v3
109+
110+
- run: echo "IMAGE_TAG=$(date --utc +%Y%m%d)-$(git rev-list ${{ github.sha }} --count)" >> "$GITHUB_ENV"
111+
112+
- name: Create manifest list and push
113+
working-directory: ${{ runner.temp }}/digests
114+
run: |
115+
docker buildx imagetools create \
116+
-t ${{ env.REGISTRY_IMAGE }}:latest \
117+
-t ${{ env.REGISTRY_IMAGE }}:${{ env.IMAGE_TAG }} \
118+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
119+
120+
- name: Inspect image
121+
run: |
122+
docker buildx imagetools inspect "${{ env.REGISTRY_IMAGE }}:latest"

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## Version 0.0.0 (Initial)
4+
5+
- java and rust sdks

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2025 Meteroid (https://meteroid.com)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

codegen/src/api/resources.rs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::cli_v1::IncludeMode;
1010

1111
use super::{
1212
get_schema_name,
13-
types::{FieldType, serialize_field_type, resolve_schema_ref_in_field_type_public},
13+
types::{FieldType, resolve_schema_ref_in_field_type_public, serialize_field_type},
1414
};
1515

1616
/// The API operations of the API client we generate.
@@ -62,7 +62,10 @@ pub(crate) fn referenced_components(resources: &Resources) -> impl Iterator<Item
6262

6363
/// Resolve SchemaRef inner types in resources (operation query params).
6464
/// This allows to_java() and similar methods to properly convert string aliases to their base types.
65-
pub(crate) fn resolve_schema_refs_in_resources(resources: &mut Resources, string_alias_names: &BTreeSet<String>) {
65+
pub(crate) fn resolve_schema_refs_in_resources(
66+
resources: &mut Resources,
67+
string_alias_names: &BTreeSet<String>,
68+
) {
6669
for resource in resources.values_mut() {
6770
resolve_schema_refs_in_resource(resource, string_alias_names);
6871
}
@@ -467,9 +470,9 @@ fn enforce_string_parameter(parameter_data: &openapi::ParameterData) -> anyhow::
467470
// Handle OpenAPI 3.1 type arrays like ["string", "null"]
468471
if let Some(schemars::schema::SingleOrVec::Vec(types)) = &obj.instance_type {
469472
let has_string = types.contains(&InstanceType::String);
470-
let all_string_or_null = types.iter().all(|t| {
471-
*t == InstanceType::String || *t == InstanceType::Null
472-
});
473+
let all_string_or_null = types
474+
.iter()
475+
.all(|t| *t == InstanceType::String || *t == InstanceType::Null);
473476
if has_string && all_string_or_null {
474477
return Ok(());
475478
}
@@ -478,30 +481,31 @@ fn enforce_string_parameter(parameter_data: &openapi::ParameterData) -> anyhow::
478481
// Handle oneOf patterns like: oneOf: [{type: null}, {$ref: ...}] or oneOf: [{type: null}, {type: string}]
479482
if let Some(ref subschemas) = obj.subschemas
480483
&& let Some(ref one_of) = subschemas.one_of
481-
&& one_of.len() == 2 {
482-
for schema in one_of {
483-
if let Schema::Object(inner_obj) = schema {
484-
// Check if this is a null type - skip it
485-
let is_null = match &inner_obj.instance_type {
486-
Some(schemars::schema::SingleOrVec::Single(t)) => **t == InstanceType::Null,
487-
_ => false,
488-
};
489-
if is_null {
490-
continue;
491-
}
484+
&& one_of.len() == 2
485+
{
486+
for schema in one_of {
487+
if let Schema::Object(inner_obj) = schema {
488+
// Check if this is a null type - skip it
489+
let is_null = match &inner_obj.instance_type {
490+
Some(schemars::schema::SingleOrVec::Single(t)) => **t == InstanceType::Null,
491+
_ => false,
492+
};
493+
if is_null {
494+
continue;
495+
}
492496

493-
// Check if this is a string type
494-
if inner_obj.instance_type == Some(InstanceType::String.into()) {
495-
return Ok(());
496-
}
497+
// Check if this is a string type
498+
if inner_obj.instance_type == Some(InstanceType::String.into()) {
499+
return Ok(());
500+
}
497501

498-
// Check if this is a $ref (path params with refs are typically string IDs)
499-
if inner_obj.reference.is_some() {
500-
return Ok(());
501-
}
502-
}
502+
// Check if this is a $ref (path params with refs are typically string IDs)
503+
if inner_obj.reference.is_some() {
504+
return Ok(());
503505
}
504506
}
507+
}
508+
}
505509

506510
// If instance_type is None but there's a $ref, accept it (typically string IDs)
507511
if obj.instance_type.is_none() && obj.reference.is_some() {

0 commit comments

Comments
 (0)