Skip to content
Back to skills

Skmtc Lang Java

ASecurity

The Java target-language layer for Skmtc generators (@skmtc/lang-java). It covers the projection base factories for a model, an operation and an Index, JavaSnippet, the register shape with full type names, the three identifier kinds, one folder as one package, a public type in the file of its name, declarations that render themselves, nested types for inline schemas, methods as members of a class, and the producers for records, enums, classes, methods, annotations, doc comments and names. It ...

  • 20 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
developmentgojavanodegitapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned December 3, 2026

npx -y skills add skmtc/skmtc --skill skmtc-lang-java --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Skmtc Lang Java?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Skmtc Lang Java
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/skmtc-skmtc-lang-java/badge)](https://www.skillsdirectory.com/skills/skmtc-skmtc-lang-java)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: skmtc-lang-java
version: 0.2.0
description: >
  The Java target-language layer for Skmtc generators (@skmtc/lang-java).
  It covers the projection base factories for a model, an operation and
  an Index, JavaSnippet, the register shape with full type names, the
  three identifier kinds, one folder as one package, a public type in the
  file of its name, declarations that render themselves, nested types for
  inline schemas, methods as members of a class, and the producers for
  records, enums, classes, methods, annotations, doc comments and names.
  It has the conventions of the reference Java SDK. Use ALONGSIDE
  skmtc-generator whenever a generator writes Java.
metadata:
  internal: true
---

# The Java layer (@skmtc/lang-java)

Read `skmtc-generator` first. There are two worked examples:

- `@skmtc/gen-java-jackson` is a model generator.
- `@skmtc/gen-java-http` is an SDK. It has an Index for each service, and
  an accumulator for the class that gives the services.

Generated code needs Java 17 or later.

## 1. Declare the language

The import graph declares the language. `src/base.ts` imports a factory,
and each snippet extends `JavaSnippet`. Import each module by its own
path, and not from the package root.

```ts fragment
import { JavaName } from '@skmtc/lang-java/JavaName'
import { toJavaModelProjectionBase } from '@skmtc/lang-java/toJavaModelProjectionBase'

export const JacksonBase = toJavaModelProjectionBase<EnrichmentSchema>({
  id: denoJson.name,
  toIdentifierName: ({ ref }) => new JavaName(toModelName(ref)).toTypeName(),
  toIdentifierType: () => ({ type: 'type' }),
  toExportPath({ ref, enrichments, variant }) {
    const name = this.toIdentifierName({ ref, enrichments, variant })

    return `@/${name}.java`
  },
})
```

The factories are `toJavaModelProjectionBase`,
`toJavaOasOperationProjectionBase` and `toJavaOasOperationIndexBase`.

## 2. A folder is a package

- **A public type is in the file of its name.** `Order` is in
  `Order.java`. Name the file after the type in `toExportPath`.
- **The project sets `settings.generatedSuffix` to `""`.** With the
  default suffix the engine names the file `Order.generated.java`, and
  `javac` refuses it. Each test of a generator sets it too.
- **A folder is a package.** The `package` line comes from the folders
  of the file: those of `settings.basePath`, then those of the export
  path (`JavaPackage`). With a folder named `java` among them
  (`./src/main/java/com/acme/orders`), the package is the folders below
  the last one: `com.acme.orders`. With none, it is the last folder.
  With no folder that Java can name, it is `api`.
- **Each name is in the whole package.** `toNameScope` gives the folder
  of a file. The engine gives the second model of one name in a folder a
  counter. It keeps that model in the file of the first, and `javac`
  refuses the file. Give one of the two another name in `base.ts`.
- **A type with no file of its own is a nested type.** The type of a
  file declares each inline object and each inline enum that the file
  reads (section 11).

## 3. Register

| Caller | Call | File |
|---|---|---|
| Projection | `this.register(args)` | Its own export file |
| Projection | `this.registerInto(path, args)` | The file you name |
| Snippet | `this.register({ ...args, destinationPath })` | The file you name |

`args` is `{ imports?, definitions?, custom? }`. There is no `reExports`.

- Java imports a type by its full name: `imports: ['java.util.List']`.
- **`JavaTypeName` renders the simple name and registers the import.**
  The producer that writes a type of a library makes one in its
  constructor, and writes it in its template:

  ```ts fragment
  this.list = new JavaTypeName({ context, destinationPath, qualifiedName: 'java.util.List' })
  // toString(): `${this.list}<${this.items}>`
  ```

- A file renders no import for a type of its own package, and none for
  a type of `java.lang`. So `java.lang.String` is a `qualifiedName` like
  any other, and a producer needs no branch for it.
- The engine registers an import for a definition in another file. The
  file renders it with the package of that file.
- Java has no alias for an import. A file cannot import two types of one
  simple name. A model named as a type that the file reads (`List`)
  hides that type. Give such a model another name in `base.ts`
  (`reservedNames` in `gen-java-jackson/src/base.ts`).
- The file renders its imports sorted. With no `custom`, it starts with
  `// Code generated by Skmtc. DO NOT EDIT.`.

## 4. Identifier kinds

| Kind | Factory | Where the declaration goes |
|---|---|---|
| `type` | `createType(name)` | At the top of a file of its name |
| `nestedType` | `createNestedType(name)` | Inside the type of its file |
| `method` | `createMethod(name)` | Inside the class that is its Index |

- A record, an enum, a class and an interface are all the kind `type`.
  Java has one namespace for the four. So `toIdentifierType` is
  `() => ({ type: 'type' })`, and reads no schema.
- You make a `nestedType` with `JavaNestedType` (section 11), and not
  with the factory.
- A `method` is a member of a class, and never a declaration of a file.
  Its projection states `toIndex` (section 6).
- Java has no alias. A model that is an array, a map or a scalar is a
  type of its own. `gen-java-jackson` declares it as a record with the
  one component `value`.

## 5. Head and value

In Java the value renders the head too. A doc comment, the annotations
and the return type of a method are all before the name, and only the
value has them. So the identifier renders its name only, the definition
renders its value only, and one of these producers renders all of the
declaration:

| Producer | Renders |
|---|---|
| `JavaRecord({ name, javadoc?, annotations?, components, interfaces?, members? })` | `public record Order(…) implements Pet {…}` |
| `JavaEnum({ name, javadoc?, annotations?, constants })` | `public enum OrderStatus {…}` |
| `JavaClass({ name, javadoc?, annotations?, members })` | `public final class PetsService {…}` |
| `JavaSealedInterface({ name, javadoc?, annotations?, permits, members? })` | `public sealed interface Pet permits Cat, Dog {…}` |
| `JavaMethod({ name, javadoc?, annotations?, returnType?, parameters?, exceptions?, statements })` | `public Pet getPet(Long petId) throws IOException {…}` |

Give the producer the name of the identifier:
`settings.identifier.name`. A projection holds one producer and renders
it:

```ts fragment
export class Service extends ServiceBase {
  declaration: JavaClass

  constructor(args: OasOperationIndexConstructorArgs<EnrichmentSchema>) {
    super(args)

    this.declaration = new JavaClass({ name: this.settings.identifier.name, members: […] })
  }

  override toString(): string {
    return `${this.declaration}`
  }
}
```

A generator class for one kind of declaration extends the producer, and
has a constructor only:

```ts fragment
export class JacksonEnum extends JavaEnum {
  constructor({ context, destinationPath, name, values, description }: JacksonEnumArgs) {
    super({ name, javadoc: new JavaDoc({ text: description }), constants: … })
  }
}
```

A record has no comment on a component. Describe each component with a
`JavaDocParam` in the `JavaDoc` of the record. With no `returnType`, a
`JavaMethod` is `void`.

## 6. A method is a member of a type

An Index is a class, and its members are its methods. Give the
`definitions` array of the Index to the `members` of its `JavaClass`:

```ts fragment
this.declaration = new JavaClass({
  name,
  members: [
    new JavaField({ name: CLIENT_NAME, type: CLIENT_TYPE }),
    new JavaConstructor({ name, parameters: […], statements: […] }),
    this.definitions,
    toNestedTypes(context, exportPath),
  ],
})
```

The methods arrive after the constructor, and the class reads the array
when it renders. Give it the array itself, and not a copy. A member
projection states `toIndex: () => TheIndex` and no `toExportPath`. An
Index of this package holds methods only.

The worked example is `@skmtc/gen-java-http`. `Service.ts` is the Index,
and `ServiceMethod.ts` is the member. Both bases are in `base.ts`. The
file of the Index reads `base.ts`, so `base.ts` cannot import the Index.
The base of the member is thus a function that takes the Index:
`toServiceMethodBase(Service)`.

## 7. Absent values

Every type of a component can be `null`, and `null` is the absent value.
Write the class of a number or a boolean (`Long`, `Boolean`), and not
the primitive (`long`). `0` is a value of its own, and a generic type
takes a class only. So a required value and an optional value have one
form, and a producer has no modifier to apply.

A record with `@JsonInclude(NON_NULL)` does not write a `null`. A
required property that is nullable has no absent value. So
`gen-java-jackson` gives its component `@JsonInclude(ALWAYS)`.

A record holds a reference, so a model refers to itself, and to a model
of its own cycle, by name. A cycle needs no other form.

## 8. Indentation

A producer renders its own lines from column 0. `JavaBlock`,
`JavaComponents`, `JavaChain` and `JavaIndented` are the only code that
indents, by two spaces for each level. A line that continues a statement
(`JavaChain`) is two levels deeper. Do not write an indent in a
template. A project sets `settings.formatter` to its own formatter.

## 9. Producers

Section 5 has the five declarations. These are the parts:

| Producer | Renders |
|---|---|
| `JavaComponent({ name, type, annotations? })` | `@JsonProperty("id") String id` |
| `JavaEnumConstant({ name, annotations? })` | `@JsonProperty("pending") PENDING` |
| `JavaField({ name, type })` | `private final ApiClient client;` |
| `JavaConstructor({ name, annotations?, parameters, statements })` | `public PetsService(ApiClient client) {…}` |
| `JavaCompactConstructor({ name, annotations? })` | `public Tags {}`, the constructor of a record that takes an annotation |
| `JavaParameter({ name, type })` | `Long petId` |
| `JavaAssignment({ field, value })` | `this.client = client;` |
| `JavaReturn(value)` | `return client;` |
| `JavaNew({ type, arguments? })` | `new PetsService(client)` |
| `JavaChain({ receiver, calls })` | A value, and each call on a line of its own below it |
| `JavaAnnotation({ name, arguments? })` | `@JsonValue`, `@JsonProperty("id")` |
| `JavaElementValue({ name, value })` | `ignoreUnknown = true`, a named argument of an annotation |
| `JavaElementArray(values)` | `{"a", "b"}`, the values of one argument of an annotation |
| `JavaClause({ keyword, types })` | ` throws IOException`, ` implements Pet`, ` permits Cat, Dog`. Nothing for no type |
| `JavaAnnotations.toLines(items)`, `.toInline(items)` | Each annotation with a line break, or with a space, after it. Nothing for none |
| `JavaTypeName({ context, destinationPath, qualifiedName })` | The simple name, with its import in the file |
| `JavaMember({ owner, name })` | `JsonInclude.Include.NON_NULL` |
| `JavaNestedType({ context, destinationPath, declaration })` | The name of a type that the file declares inside its own type |
| `JavaStringLiteral(value)` | `"pending"`, with each escape |
| `JavaPathTemplate(path)` | `"/pets/{petId}"`, with each name in `placeholders` |
| `JavaDoc({ text?, paragraphs?, params?, returns? })`, `JavaDocParam({ name, text })` | A doc comment with a line break after it, or nothing |
| `JavaDocText(text)` | Text that a doc comment can hold |
| `JavaList.toArguments(items)`, `.toCommaLines`, `.toLines`, `.toParagraphs` | `a, b`; one item on each line with a comma between; one item on each line; a blank line between items |
| `JavaBlock(items)`, `JavaBlock.toLines(items)` | `{`, the items one level deeper, `}`. `{}` for none |

- An item that is `undefined` or `null` is absent.
- An item of a `JavaBlock`, and of the `members` of a record or a class,
  can be a list. The block reads each list when it renders, so a list
  that grows later is complete in the output.
- **A constructor stores producers and facts. Only `toString()` holds
  Java code.** Do not write `` `this.${name} = ${name};` `` in a
  constructor: that is a `JavaAssignment`. Do not store the result of a
  template in a field.
- **An annotation of a library is a class on `JavaAnnotation`**, with a
  constructor only:

  ```ts fragment
  export class JacksonIgnoreUnknown extends JavaAnnotation {
    constructor({ context, destinationPath }: AnnotationArgs) {
      super({
        name: new JavaTypeName({ context, destinationPath, qualifiedName: JSON_IGNORE_PROPERTIES }),
        arguments: new JavaElementValue({ name: 'ignoreUnknown', value: true }),
      })
    }
  }
  ```

- The `text` of a `JavaDoc` is the first paragraph. Each item of
  `paragraphs` is a later paragraph, and starts with `<p>`. `returns` is
  the text of the `@return` line. A part with no text renders nothing.
- An annotation with more than one argument takes a
  `JavaList.toArguments([…])` of `JavaElementValue` items.
- Java has no string with values in it. `JavaPathTemplate` keeps each
  `{name}` of an OpenAPI path in the literal. The hand-written code that
  sends the request puts a value in its place.

## 10. Names and literals

- `new JavaName(text).toTypeName()` for a record, an enum and a class:
  `pet_id` gives `PetId`. `.toMemberName()` for a component, a parameter
  and a method: `petId`. `.toConstantName()` for a constant of an enum:
  `PET_ID`. Each form is a valid Java name for any text. A word keeps
  the capitals that the document gave it (`HTTPServer`). A text with no
  letter and no digit gives `X`, `x` and `X`.
- A word that starts with a digit keeps the lower-case letters after
  the digit: `2nd line` gives `_2ndLine`.
- A name can have two or more texts. `new JavaName('ShipTo', 'address')`
  gives `ShipToAddress`. An inline schema gets its name in this way
  (section 11).
- `toMemberName()` adds an underscore to the end of a reserved word:
  `class_`. It does the same for a method of `Object` that Java refuses
  as a record component: `hashCode_`.
- `new JavaNameScope(reserved).claim(name)` gives each name of one list
  a different value. Use it for the components of a record, the
  constants of an enum and the parameters of a method. Two keys can give
  one Java name (`user-id` and `user_id`).
- `new JavaStringLiteral(value)` writes a string of the document as a
  Java string. Use it for each key and enum value.
- `JavaDoc` writes a description through `JavaDocText`. Do not write a
  description into a comment in a template. `*/` ends the comment. Java
  also reads a backslash and `u` as an escape in a comment.

## 11. A declaration and a type position differ

A model that is an object with properties is a record. An inline object
with properties is only the name of a record. A string with an enum
differs in the same way. `gen-java-jackson` solves this as follows:

- **One router, with the position as an argument.** `toJacksonValue`
  takes an optional `model`: the name of the model and the nested types
  of its file. With `model`, the producer of an object, a string or a
  union renders the declaration. With none, it renders a type.
- **The producer chooses its form in its constructor.** `JacksonObject`
  makes a record for a model, and a `JavaNestedType` for an inline
  object. No second router does this.
- **An inline schema is a nested type.** In a type position, an inline
  object takes a name and makes its record. It gives the record to a
  `JavaNestedType`, which renders the name:

  ```ts fragment
  const name = claimNestedName(context, { destinationPath, name: inlineName, hidden })

  new JavaNestedType({
    context,
    destinationPath,
    declaration: new JacksonRecord({ context, destinationPath, objectSchema, name, holder: name, nestedTypes: [] }),
  })
  ```

  The declaration goes into the list of nested types of the file. The
  type of the file renders that list in its body: give
  `toNestedTypes(context, exportPath)` to its `members`. A file whose
  type does not take the list loses its nested types.
- **The name of an inline schema is its place in its file.** The caller
  passes it down: `inlineName` in the arguments of the router. The
  functions that make it are in `base.ts`.
  - The record of a model passes the key: `ShipTo`.
  - A nested record passes its own name and the key: `ShipToAddress`.
  - An array adds `Item`, and a map adds `Value`.
  - An operation generator passes the name of its method and the role of
    the schema: `CreateApiPetsBody`, `GetApiPetsResponse`.
  - The parameter `status` gives `GetApiPetsStatusParam`.
  - No code reads the `stackTrail` of the schema.
- **`claimNestedName` gives each nested type of a file a name of its
  own.** The second nested type that asks for one name gets a number:
  `ShipTo2`. A nested type also gets a number when it asks for the name
  of the type of its file.
- **A nested type hides a type of its package that has its name.** A
  `$ref` in the same file then reads the nested type, and `javac`
  accepts it. Give `claimNestedName` the names that the file can read in
  `hidden`. `gen-java-jackson` gives the name of each model of the
  document. It also gives each type of Java and of Jackson that it
  writes (`toNestedName` in its `base.ts`).
- **Two nested types of one name stop the run.** `JavaFile` throws when
  a nested type has the name of another declaration of its file. A
  generator that takes each name with `claimNestedName` never gets this
  error.

## 11a. A union is a sealed interface

A `oneOf` with a discriminator is a `JavaSealedInterface`, and the record
of each member implements it. Java declares the interface of a record in
the record. The engine can build a model before the union that names
it.

- Read the unions of the document one time, and keep the result for the
  run. `SealedUnions` in `gen-java-jackson` does this. `toSealedUnions`
  in its `base.ts` keeps one result for each document.
- Core says if the discriminator alone picks the member:
  `union.isDiscriminable()`. Do not write that test again.
- The record of a member gets `interfaces: [name]`, and `@JsonTypeName`
  with its value of the discriminator. It has no component for the
  discriminator.
- The interface names an `Unknown` record as its `defaultImpl`. A new
  member of the API then does not stop the read.
- A union that does not qualify is `JsonNode`.

## 12. Pitfalls

| Symptom | Fix |
|---|---|
| `class Order is public, should be declared in a file named Order.java` | Set `settings.generatedSuffix` to `""`. If the file is the one of another model (`PetStatus2` in `PetStatus.java`), two models give one name: give one of them another name in `base.ts` |
| `cannot find symbol: class List` | The producer that writes `List` did not make a `JavaTypeName` for it |
| `cannot find symbol: class ShipTo` | The type of the file did not get `toNestedTypes(context, exportPath)` in its `members` |
| `Cannot declare the nested type 'ShipTo' in '@/Order.java'` | Two nested types of one file have one name. Take each name with `claimNestedName` |
| A `$ref` reads a nested type, and not the model of that name | The nested type hides the model. Give `claimNestedName` the names of the models in `hidden` |
| `unreported exception java.io.IOException` | A method calls code that throws. Give the `JavaMethod` its `exceptions` |
| `a type with the same simple name is already defined` | A model has the name of a type that its file imports. Give the model another name in `base.ts` |
| `incompatible types` at a `String` or a `List` | A model of that name hides the type of Java in the package. Give the model another name in `base.ts` |
| `illegal unicode escape` | A description was written into a comment as it is. Write it through `JavaDoc` |
| `illegal record component name hashCode` | The name of a component did not come from `JavaName.toMemberName()` |
| `record component x is already defined` | Two keys give one name. Claim each name in a `JavaNameScope` |
| A declaration has no `public record Order` before its components | The projection renders a part, and not a `JavaRecord`. The value renders all of the declaration (section 5) |
| A class renders with no methods | The `JavaClass` got a copy of `definitions`. Give it the array itself |
| `this Index does not hold that kind of declaration` | A member of a class Index is not a `method`. Declare a record or an enum as a nested type, with `JavaNestedType` |
| `skmtc/single-dispatch` reports a router | Name it `to<X>Value`, and keep one router in a generator |

## The reference SDK

The style of the Java output is that of
[line-bot-sdk-java](https://github.com/line/line-bot-sdk-java), the
official SDK of LINE, read at commit
`871243ca4da4b3e89af042f53b8f3f3136c1876b` (Apache-2.0, Java 17, Jackson
2). It is the one well-known SDK whose models are records with Jackson
annotations. Its client is on Retrofit, so the models and the method
signatures come from it, and the method body is ours.

Its conventions, and what the two generators do with each:

| Convention of the reference | In our output |
|---|---|
| One top-level type for each file, named after the type, with a "do not edit" comment first | The same |
| A model is a `record`, with one component for each property, in schema order | The same |
| `PascalCase` types, `camelCase` components, and the wire name always in `@JsonProperty` | The same |
| Optional and nullable are both a `null` reference, with no `Optional<T>`. Numbers and booleans are boxed. The record has `@JsonInclude(Include.NON_NULL)` | The same. A record does not write the `null` of an optional property |
| Required properties do not show in the type | The same |
| A string enum is a Java `enum` with `@JsonProperty` on each constant and an `UNDEFINED` constant with `@JsonEnumDefaultValue` last | The same. The `ObjectMapper` turns on `READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE` |
| An inline enum is a nested enum in the record that uses it, named after the property | The same, and an inline object is a nested record |
| A union with a discriminator is an interface with `@JsonTypeInfo` and `@JsonSubTypes`. Each member `implements` it, has `@JsonTypeName`, and has no component for the discriminator. An `Unknown` type takes a value that the interface does not know | The same, for a union that is a component. The `Unknown` type is a nested record of the interface |
| Arrays are `List<T>` and maps are `Map<String, T>` | The same |
| `int64` is `Long`, `int32` is `Integer`, `number` is `Double`, `uuid` is `UUID`, `date-time` is `OffsetDateTime`, a URI is `URI` | The same. An integer with no format is `Long` |
| Javadoc from the description, on the type | The same. A record describes each component with `@param`, which the `javadoc` tool reads |
| Parameters are plain positional arguments, in the order of the document, and the body is last. An optional parameter is a nullable reference | The same |
| The body argument has the name of its type in `camelCase` | The same for a body that is a model. An inline body is `body` |
| The method Javadoc is the summary, then one `@param` for each argument, marked `(required)` or `(optional)` | The same, with the method and the path as a second paragraph, and a `@return` line |
| The method returns the decoded model type, and nothing when there is no body | The same, from a blocking call |
| One shared `ObjectMapper`, configured once in the runtime. Generated code never configures Jackson | The same: the hand-written `ApiClient` has it |
| Every response outside 2xx becomes one exception type, with the status and the body. The exception extends `IOException` | The same: `ApiException`. Each method declares `throws IOException, InterruptedException`, as `HttpClient.send` does |
| The hand-written runtime is small and apart from the code for each API | The same: three files in `base-files/` |

Where we differ, and why:

| The reference | Ours | Why |
|---|---|---|
| Two packages: `model` and `client` | One package | The files of one folder read each other with no import, and a project has one `basePath` |
| One client type for each API, with methods named from `operationId` | A service class for each tag, and names from the method and the path | The rule of Skmtc for the name of an operation |
| A plain `interface` for a union | A `sealed` interface | A `switch` over a sealed interface is complete with a case for each record |
| No required property shows in the JSON rules | `@JsonInclude(ALWAYS)` on a property that is required and nullable | That property has no absent value, so the record must write its `null` |
| A nested `Builder` in each record | None | It makes each model three times as long |
| `@javax.annotation.Generated` | None | It needs a dependency. The first line of the file says it |
| A Retrofit interface, with `CompletableFuture<Result<T>>` | A class on `java.net.http.HttpClient` that returns `T` | The JDK has the client, and a blocking call is the simple default |

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.