Repository: specta-rs/specta Branch: main Commit: a580a9865656 Files: 279 Total size: 2.9 MB Directory structure: gitextract_unw2xfqn/ ├── .github/ │ ├── FUNDING.yml │ ├── dependabot.yml │ ├── features.js │ └── workflows/ │ └── ci.yml ├── .gitignore ├── .rustfmt.toml ├── .taplo.toml ├── AGENTS.md ├── Cargo.toml ├── LICENSE ├── README.md ├── examples/ │ ├── basic-ts/ │ │ ├── Cargo.toml │ │ └── src/ │ │ └── main.rs │ ├── collect/ │ │ ├── Cargo.toml │ │ └── src/ │ │ └── main.rs │ └── scratchpad/ │ ├── Cargo.toml │ └── src/ │ └── main.rs ├── specta/ │ ├── Cargo.toml │ ├── build.rs │ └── src/ │ ├── collect.rs │ ├── datatype/ │ │ ├── attributes.rs │ │ ├── enum.rs │ │ ├── fields.rs │ │ ├── function.rs │ │ ├── generic.rs │ │ ├── list.rs │ │ ├── literal.rs │ │ ├── map.rs │ │ ├── named.rs │ │ ├── primitive.rs │ │ ├── reference.rs │ │ ├── struct.rs │ │ └── tuple.rs │ ├── datatype.rs │ ├── docs.md │ ├── format.rs │ ├── function/ │ │ ├── arg.rs │ │ ├── result.rs │ │ └── specta_fn.rs │ ├── function.rs │ ├── internal.rs │ ├── lib.rs │ ├── type/ │ │ ├── impls.rs │ │ ├── legacy_impls.rs │ │ └── macros.rs │ ├── type.rs │ └── types.rs ├── specta-go/ │ ├── Cargo.toml │ ├── bindings.go │ └── src/ │ ├── error.rs │ ├── go.rs │ ├── lib.rs │ ├── primitives.rs │ └── reserved_names.rs ├── specta-jsonschema/ │ ├── Cargo.toml │ ├── examples/ │ │ └── jsonschema.rs │ ├── src/ │ │ ├── error.rs │ │ ├── import.rs │ │ ├── json_schema.rs │ │ ├── layout.rs │ │ ├── lib.rs │ │ ├── primitives.rs │ │ └── schema_version.rs │ └── tests/ │ └── basic.rs ├── specta-kotlin/ │ ├── Cargo.toml │ └── src/ │ └── lib.rs ├── specta-macros/ │ ├── Cargo.toml │ ├── README.md │ └── src/ │ ├── lib.rs │ ├── specta.rs │ ├── type/ │ │ ├── attr/ │ │ │ ├── container.rs │ │ │ ├── field.rs │ │ │ ├── legacy.rs │ │ │ ├── mod.rs │ │ │ ├── rustc.rs │ │ │ └── variant.rs │ │ ├── enum.rs │ │ ├── field.rs │ │ ├── generics.rs │ │ ├── mod.rs │ │ ├── serde.rs │ │ └── struct.rs │ └── utils.rs ├── specta-openapi/ │ ├── Cargo.toml │ └── src/ │ └── lib.rs ├── specta-serde/ │ ├── Cargo.toml │ ├── README.md │ └── src/ │ ├── error.rs │ ├── inflection.rs │ ├── lib.rs │ ├── parser.rs │ ├── phased.rs │ ├── repr.rs │ └── validate.rs ├── specta-swift/ │ ├── Cargo.toml │ ├── README.md │ ├── Types.swift │ ├── examples/ │ │ ├── README.md │ │ ├── advanced_unions.rs │ │ ├── basic_types.rs │ │ ├── comments_example.rs │ │ ├── comprehensive_demo.rs │ │ ├── configuration_options.rs │ │ ├── generated/ │ │ │ ├── AdvancedUnions.swift │ │ │ ├── BasicTypes.swift │ │ │ ├── CamelCase.swift │ │ │ ├── CombinedConfig.swift │ │ │ ├── CommentsExample.swift │ │ │ ├── ComprehensiveDemo.swift │ │ │ ├── CustomHeader.swift │ │ │ ├── CustomTypes.swift │ │ │ ├── DefaultConfig.swift │ │ │ ├── OptionalType.swift │ │ │ ├── PascalCase.swift │ │ │ ├── ProtocolGenerics.swift │ │ │ ├── QuestionMark.swift │ │ │ ├── SimpleTypes.swift │ │ │ ├── SnakeCase.swift │ │ │ ├── Spaces2.swift │ │ │ ├── Spaces4.swift │ │ │ ├── SpecialTypes.swift │ │ │ ├── StringEnums.swift │ │ │ ├── Tabs.swift │ │ │ ├── TypealiasGenerics.swift │ │ │ ├── WithProtocols.swift │ │ │ └── WithSerde.swift │ │ ├── simple_usage.rs │ │ ├── special_types.rs │ │ └── string_enums.rs │ ├── src/ │ │ ├── error.rs │ │ ├── lib.rs │ │ ├── primitives.rs │ │ └── swift.rs │ └── tests/ │ ├── Cargo.toml │ ├── advanced_unions.rs │ ├── basic.rs │ ├── common_types.rs │ ├── comprehensive.rs │ ├── multiline_comments.rs │ ├── string_enum_implementation.rs │ ├── string_enum_test.rs │ ├── struct_reuse_test.rs │ ├── struct_variants.rs │ ├── unions.rs │ ├── uuid_simple.rs │ └── uuid_test.rs ├── specta-tags/ │ ├── Cargo.toml │ └── src/ │ └── lib.rs ├── specta-typescript/ │ ├── Cargo.toml │ ├── bindings.ts │ └── src/ │ ├── branded.rs │ ├── error.rs │ ├── exporter.rs │ ├── jsdoc.rs │ ├── legacy.rs │ ├── lib.rs │ ├── map_keys.rs │ ├── opaque.rs │ ├── primitives.rs │ ├── references.rs │ ├── reserved_names.rs │ ├── types.rs │ └── typescript.rs ├── specta-util/ │ ├── Cargo.toml │ └── src/ │ ├── array.rs │ ├── lib.rs │ ├── remapper.rs │ └── selection.rs ├── specta-zod/ │ ├── Cargo.toml │ └── src/ │ ├── error.rs │ ├── lib.rs │ ├── opaque.rs │ ├── primitives.rs │ ├── references.rs │ ├── reserved_names.rs │ ├── types.rs │ └── zod.rs └── tests/ ├── Cargo.toml └── tests/ ├── bound.rs ├── errors.rs ├── functions.rs ├── jsdoc.rs ├── layouts.rs ├── legacy_impls.rs ├── macro/ │ ├── compile_error.rs │ └── compile_error.stderr ├── mod.rs ├── references.rs ├── serde_conversions.rs ├── serde_identifiers.rs ├── serde_other.rs ├── snapshots/ │ ├── test__bound__bound-associated-type-issue-138.snap │ ├── test__jsdoc__export-many-raw.snap │ ├── test__jsdoc__export-many-serde.snap │ ├── test__jsdoc__export-many-serde_phases.snap │ ├── test__jsdoc__export-raw.snap │ ├── test__jsdoc__export-serde.snap │ ├── test__jsdoc__export-serde_phases.snap │ ├── test__jsdoc__inline-raw.snap │ ├── test__jsdoc__inline-serde.snap │ ├── test__jsdoc__inline-serde_phases.snap │ ├── test__jsdoc__jsdoc-export-to-files-both.snap │ ├── test__jsdoc__jsdoc-export-to-files-raw.snap │ ├── test__jsdoc__jsdoc-export-to-files-serde.snap │ ├── test__jsdoc__jsdoc-export-to-files-serde_phases.snap │ ├── test__jsdoc__jsdoc-export-to-flatfile-raw.snap │ ├── test__jsdoc__jsdoc-export-to-flatfile-serde.snap │ ├── test__jsdoc__jsdoc-export-to-flatfile-serde_phases.snap │ ├── test__jsdoc__jsdoc-export-to-moduleprefixedname-raw.snap │ ├── test__jsdoc__jsdoc-export-to-moduleprefixedname-serde.snap │ ├── test__jsdoc__jsdoc-export-to-moduleprefixedname-serde_phases.snap │ ├── test__jsdoc__jsdoc-export-to-namespaces-raw.snap │ ├── test__jsdoc__jsdoc-export-to-namespaces-serde.snap │ ├── test__jsdoc__jsdoc-export-to-namespaces-serde_phases.snap │ ├── test__jsdoc__primitives-many-inline-raw.snap │ ├── test__jsdoc__primitives-many-inline-serde.snap │ ├── test__jsdoc__primitives-many-inline-serde_phases.snap │ ├── test__jsdoc__reference-raw.snap │ ├── test__jsdoc__reference-serde.snap │ ├── test__jsdoc__reference-serde_phases.snap │ ├── test__layouts__layouts-duplicate-files.snap │ ├── test__layouts__layouts-duplicate-module-prefixed.snap │ ├── test__layouts__layouts-duplicate-namespaces.snap │ ├── test__layouts__layouts-empty-module-path-files.snap │ ├── test__layouts__layouts-empty-module-path-flat.snap │ ├── test__layouts__layouts-empty-module-path-module-prefixed.snap │ ├── test__layouts__layouts-empty-module-path-namespaces.snap │ ├── test__layouts__layouts-non-duplicate-default.snap │ ├── test__layouts__layouts-non-duplicate-files.snap │ ├── test__layouts__layouts-non-duplicate-flat.snap │ ├── test__layouts__layouts-non-duplicate-module-prefixed.snap │ ├── test__layouts__layouts-non-duplicate-namespaces.snap │ ├── test__legacy_impls__legacy_impls.snap │ ├── test__serde_conversions__serde-conversions-format-phases-exports-field-only-phased-override.snap │ ├── test__serde_conversions__serde-conversions-format-phases-splits-container-and-dependents.snap │ ├── test__serde_identifiers__serde-identifiers-field-typescript.snap │ ├── test__serde_identifiers__serde-identifiers-variant-typescript.snap │ ├── test__serde_other__serde-other-adjacent-tag-typescript.snap │ ├── test__serde_other__serde-other-internal-tag-typescript.snap │ ├── test__swift__swift-export-raw.snap │ ├── test__swift__swift-export-serde.snap │ ├── test__swift__swift-export-serde_phases.snap │ ├── test__types__serde-default-container-typescript.snap │ ├── test__types__serde-default-field-typescript.snap │ ├── test__types__serde-mixed-untagged-phased-typescript.snap │ ├── test__types__serde-mixed-untagged-struct-typescript.snap │ ├── test__types__serde-mixed-untagged-typescript.snap │ ├── test__typescript__export-many-raw.snap │ ├── test__typescript__export-many-serde.snap │ ├── test__typescript__export-many-serde_phases.snap │ ├── test__typescript__export-raw.snap │ ├── test__typescript__export-serde.snap │ ├── test__typescript__export-serde_phases.snap │ ├── test__typescript__inline-raw.snap │ ├── test__typescript__inline-serde.snap │ ├── test__typescript__inline-serde_phases.snap │ ├── test__typescript__reference-raw.snap │ ├── test__typescript__reference-serde.snap │ ├── test__typescript__reference-serde_phases.snap │ ├── test__typescript__ts-export-raw.snap │ ├── test__typescript__ts-export-serde.snap │ ├── test__typescript__ts-export-serde_phases.snap │ ├── test__typescript__ts-export-to-files-raw.snap │ ├── test__typescript__ts-export-to-files-serde.snap │ ├── test__typescript__ts-export-to-files-serde_phases.snap │ ├── test__typescript__ts-export-to-flatfile-raw.snap │ ├── test__typescript__ts-export-to-flatfile-serde.snap │ ├── test__typescript__ts-export-to-flatfile-serde_phases.snap │ ├── test__typescript__ts-export-to-moduleprefixedname-raw.snap │ ├── test__typescript__ts-export-to-moduleprefixedname-serde.snap │ ├── test__typescript__ts-export-to-moduleprefixedname-serde_phases.snap │ ├── test__typescript__ts-export-to-namespaces-raw.snap │ ├── test__typescript__ts-export-to-namespaces-serde.snap │ └── test__typescript__ts-export-to-namespaces-serde_phases.snap ├── swift.rs ├── types.rs ├── typescript.rs ├── utils.rs └── zod.rs ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/FUNDING.yml ================================================ github: [oscartbeaumont] custom: ["https://paypal.me/oscartbeaumont"] ================================================ FILE: .github/dependabot.yml ================================================ version: 2 multi-ecosystem-groups: specta-deps: schedule: interval: "weekly" updates: - package-ecosystem: "github-actions" directory: "/" multi-ecosystem-group: "specta-deps" patterns: ["*"] - package-ecosystem: "cargo" directory: "/" multi-ecosystem-group: "specta-deps" patterns: ["*"] ================================================ FILE: .github/features.js ================================================ // This script generates the documentation for the Cargo features from the comments in the `Cargo.toml` file. // It dumps the result into the `src/docs.md` file. This means the docs are readable in the published version of the crate and also allows the docs to be broken into a separate file (unlike `document-features`) const fs = require("fs"); const path = require("path"); const START_MARKER = "[//]: # (FEATURE_FLAGS_START)"; const END_MARKER = "[//]: # (FEATURE_FLAGS_END)"; const docsPath = path.join(__dirname, "..", "src", "docs.md"); const cargoToml = fs.readFileSync( path.join(__dirname, "..", "Cargo.toml"), "utf8" ); const docs = fs.readFileSync(docsPath, "utf8"); if (!docs.includes(START_MARKER) || !docs.includes(END_MARKER)) throw new Error("Missing markers in 'docs.md'"); const lines = cargoToml.split("\n").map((line) => line.trim()); const featuresIndex = lines.indexOf("[features]"); if (featuresIndex === -1) throw new Error("Missing '[features]' in 'Cargo.toml'"); const featuresPart = lines.slice(featuresIndex + 1); const endIndex = featuresPart.findIndex( (line) => line.startsWith("[") && line.endsWith("]") ); const featuresLine = featuresPart.slice(0, endIndex); let comments = ""; let group = null; let result = {}; for (const line of featuresLine) { if (line == "") { continue; } if (line.startsWith("##!")) { group = ""; result[group] = {}; } else if (line.startsWith("##")) { comments += line.slice(2).trim() + "\n"; } else if (line.startsWith("#!")) { group = line.substring(2).trim(); result[group] = {}; } else if (line.startsWith("#")) { continue; } else { const parts = line.split("="); if (parts.length !== 2) throw new Error(`Invalid feature line: '${line}'`); if (group !== null) { result[group][parts[0].trim()] = comments; comments = ""; } } } let markdown_result = Object.entries(result) .map( ([name, deps]) => `${name}\n\n${Object.entries(deps) .map( ([name, comment]) => `- \`${name}\` - ${comment.replace("\n", " ").trim()}` ) .join("\n")}` ) .join("\n\n"); const resultDocs = docs.replace( docs.substring( docs.indexOf(START_MARKER), docs.lastIndexOf(END_MARKER) + END_MARKER.length ), START_MARKER + "\n" + markdown_result + "\n\n" + END_MARKER ); fs.writeFileSync(docsPath, resultDocs); ================================================ FILE: .github/workflows/ci.yml ================================================ name: CI on: workflow_dispatch: push: branches: - main pull_request: env: CARGO_TERM_COLOR: always jobs: build: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v6 - name: Setup if: matrix.os == 'ubuntu-latest' run: sudo apt-get update && sudo apt-get install libgtk-3-dev webkit2gtk-4.1 libayatana-appindicator3-dev - name: Install Rust toolchain run: rustup toolchain install stable --profile minimal - name: Rust cache uses: Swatinem/rust-cache@v2 - name: Build run: cargo build --all-features - name: Run tests run: cargo test --all-features clippy: runs-on: ubuntu-latest permissions: contents: read checks: write pull-requests: write steps: - uses: actions/checkout@v6 - name: Setup run: sudo apt-get update && sudo apt-get install libgtk-3-dev webkit2gtk-4.1 libayatana-appindicator3-dev - name: Install Rust toolchain run: rustup toolchain install stable --profile minimal --component clippy - name: Rust cache uses: Swatinem/rust-cache@v2 - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} args: --all-features ================================================ FILE: .gitignore ================================================ # Generated by Cargo # will have compiled files and executables target/ test-target/ # These are backup files generated by rustfmt **/*.rs.bk # System Files .DS_Store # Node node_modules .pnpm-debug.log* *.tsbuildinfo /packages/*/dist /bindings.ts /bindings2.ts /tests/.temp # Used by examples as a place to export files. /specta-typescript/out ================================================ FILE: .rustfmt.toml ================================================ # https://github.com/specta-rs/specta/pull/222 ================================================ FILE: .taplo.toml ================================================ [formatting] column_width = 150 ================================================ FILE: AGENTS.md ================================================ Specta is a Rust library for easily exporting Rust types to other languages (TypeScript, Swift, Rust, OpenAPI, etc.). It's a workspace with multiple crates: ``` specta/ ├── specta/ # Core library ├── specta-macros/ # Macros for the core library ├── specta-typescript/ # TypeScript exporter (stable) ├── specta-swift/ # Swift exporter (stable) ├── specta-openapi/ # OpenAPI (partial) ├── specta-serde/ # Serde utilities ├── specta-util/ # Utilities for end-users. Less semver guarantees. ├── tests/ # Integration tests ├── Cargo.toml # Workspace manifest ``` Specta is format agnostic so the `specta` and `specta-macros` crate should avoid hardcoding serde-specific behaviors. We use `insta` for snapshot testing Use Rust 2024 edition Document feature gates with `#[cfg_attr(docsrs, doc(cfg(feature = "...")))]` Prefer to put tests in the dedicated crate Don't run `cargo doc --open` as it opens a browser you can't read. Maybe prefer a web fetch to https://docs.rs/{crate_name} Prefer Rust module guidelines including using `module.rs` instead of `module/mod.rs` When testing bugs create a unit test to ensure it's fixed. If I give you a GitHub link can you include it in comments. Don't use `/tmp` for temporary projects in should stay within the workspace. You are a senior engineer. You should follow Clippy and Rust best practices. Write code that is concise and readable. Make use of Rust's method chaining where it would result in cleaner code. ================================================ FILE: Cargo.toml ================================================ [workspace] members = ["specta", "specta-*", "tests", "examples/*"] resolver = "2" [workspace.lints.rust] unsafe_code = { level = "warn", priority = -1 } # ctor requires unsafe but is an optional feature missing_docs = { level = "warn", priority = -1 } unexpected_cfgs = { level = "warn", check-cfg = ['cfg(is_nightly)'] } [workspace.lints.clippy] all = { level = "warn", priority = -1 } cargo = { level = "warn", priority = -1 } unwrap_used = { level = "warn", priority = -1 } panic = { level = "warn", priority = -1 } todo = { level = "warn", priority = -1 } panic_in_result_fn = { level = "warn", priority = -1 } multiple_crate_versions = { level = "allow", priority = 0 } # I hate these. For internal code I don't care. too_many_arguments = { level = "allow", priority = 0 } type_complexity = { level = "allow", priority = 0 } [profile.dev.package] insta.opt-level = 3 similar.opt-level = 3 ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2022 Oscar Beaumont Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================