Skip to content

Commit

Permalink
v0.2.2: fix array signature not being displayed for primitive data ty…
Browse files Browse the repository at this point in the history
…pes, zig version
  • Loading branch information
kshyr committed Jun 5, 2024
1 parent 84c2eeb commit 4073cd4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Generates JSDoc `@typedef` for every schema in OpenAPI spec.

Zig version: `0.12.0-dev.3180+83e578a18`

---
### Usage
`openapi-to-jsdoc path/to/openapi.json path/to/output.js`
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void {

const exe = b.addExecutable(.{
.name = "openapi-to-jsdoc",
.root_source_file = b.path("src/main.zig"),
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.{
.name = "openapi-to-jsdoc",
.version = "0.2.1",
.version = "0.2.2",
.paths = .{
"build.zig",
"build.zig.zon",
Expand Down
19 changes: 8 additions & 11 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,15 @@ fn get_jsdoc_type(allocator: std.mem.Allocator, value: std.json.Value, array_suf
const items = value.object.get("items").?;
const item_type = try get_jsdoc_type(allocator, items, "[]");
return item_type;
} else if (std.mem.eql(u8, type_.string, "object")) {
return "Object";
} else if (std.mem.eql(u8, type_.string, "string")) {
return "string";
} else if (std.mem.eql(u8, type_.string, "number")) {
return "number";
} else if (std.mem.eql(u8, type_.string, "integer")) {
return "number";
} else if (std.mem.eql(u8, type_.string, "boolean")) {
return "boolean";
}
return try std.fmt.allocPrint(allocator, "{s}{s}", .{ type_.string, array_suffix });

var type_str = type_.string;

if (std.mem.eql(u8, type_str, "integer")) {
type_str = "number";
}

return try std.fmt.allocPrint(allocator, "{s}{s}", .{ type_str, array_suffix });
} else {
const ref = value.object.get("$ref").?.string;
var split = std.mem.split(u8, ref, "/");
Expand Down

0 comments on commit 4073cd4

Please sign in to comment.