You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -230,7 +230,7 @@ When benchmark numbers move, profile before changing the runtime. The repo now i
230
230
- Copy from [How to model common contract patterns](docs/HOW_TO_MODEL_COMMON_CONTRACT_PATTERNS.md).
231
231
- Use [Configuration contracts guide](docs/CONFIG_CONTRACTS.md) for versioned config shapes.
232
232
- Use [How to export JSON Schema](docs/HOW_TO_EXPORT_JSON_SCHEMA.md) and [JSON Schema support reference](docs/JSON_SCHEMA_SUPPORT.md) for schema interchange.
233
-
- Use [How to import existing C# contracts](docs/HOW_TO_IMPORT_CSHARP_CONTRACTS.md)and [C# attribute bridge design](docs/CSHARP_ATTRIBUTE_BRIDGE.md)for the bridge/facade story.
233
+
- Use [How to import existing C# contracts](docs/HOW_TO_IMPORT_CSHARP_CONTRACTS.md) for the bridge/facade story.
234
234
- Browse the [API docs](https://adz.github.io/CodecMapper/).
Copy file name to clipboardExpand all lines: docs/GETTING_STARTED.md
+57-2Lines changed: 57 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,20 @@ This tutorial is learning-oriented: it introduces the main schema DSL, how to re
6
6
7
7
The portable core in `CodecMapper` is intended to stay usable from Native AOT and Fable-oriented targets. The separate `CodecMapper.Bridge` assembly is `.NET`-only because it imports CLR serializer metadata through reflection.
8
8
9
+
## Choose the right starting path
10
+
11
+
Start from the contract you already have:
12
+
13
+
- F# contract you control: author a `Schema<'T>` directly and compile it.
14
+
- New C# class you control: use `CSharpSchema` for setter-bound classes, then compile the result like any other schema.
15
+
- Existing C# contract already annotated for `System.Text.Json`, `Newtonsoft.Json`, or `DataContract`: import it through `CodecMapper.Bridge`.
16
+
- External JSON Schema document: keep that separate from authored schemas and use the JSON Schema import path only for receive-side `JsonValue` contracts.
17
+
18
+
That split matters because `CodecMapper` has two different extension stories:
19
+
20
+
- authored schemas: normal `Schema<'T>` values that compile into fast typed codecs
21
+
- imported contracts: bridge or JSON Schema flows that help you interoperate with contracts you do not want to rewrite immediately
22
+
9
23
## Core shape
10
24
11
25
The stable schema DSL is:
@@ -90,6 +104,46 @@ let personSchema =
90
104
let jsonCodec = Json.codec personSchema
91
105
```
92
106
107
+
## Starting from C#
108
+
109
+
If you are using `CodecMapper` from a C#-heavy codebase, there are two intended paths.
110
+
111
+
For new setter-bound classes, author the schema directly with `CSharpSchema`:
112
+
113
+
```csharp
114
+
usingCodecMapper;
115
+
usingCodecMapper.Bridge;
116
+
117
+
publicsealedclassUser
118
+
{
119
+
publicintId { get; set; }
120
+
publicstringName { get; set; } ="";
121
+
}
122
+
123
+
varschema=
124
+
CSharpSchema.Record(() =>newUser())
125
+
.Field("id", value =>value.Id, (value, field) =>value.Id=field)
126
+
.Field("name", value =>value.Name, (value, field) =>value.Name=field)
Use the direct C# schema path when you own the contract and want `CodecMapper` to be the source of truth. Use the bridge when an existing serializer contract is already established and you need an incremental migration path.
146
+
93
147
If you want a shorter qualified style without opening the module for the whole file, use a module alias:
94
148
95
149
```fsharp
@@ -374,5 +428,6 @@ Still out of scope:
374
428
- Use `Schema.tryMap` when decode needs validation.
375
429
- Reach for `Schema.nonEmptyString`, `Schema.trimmedString`, `Schema.positiveInt`, and `Schema.nonEmptyList` when those boundary rules are part of the contract.
376
430
- Keep schemas in one place so JSON and XML stay aligned.
377
-
- Use [How To Export JSON Schema](HOW_TO_EXPORT_JSON_SCHEMA.md) when you need external schema documents.
378
-
- Use [C# Attribute Bridge Design](CSHARP_ATTRIBUTE_BRIDGE.md) when you are importing existing C# contracts instead of authoring schemas directly.
431
+
- Treat JSON Schema as a separate integration surface: export it from authored schemas, or import it for receive-side `JsonValue` contracts.
432
+
- Use [How To Export JSON Schema](HOW_TO_EXPORT_JSON_SCHEMA.md) when you need external schema documents from authored contracts.
433
+
- Use [How To Import Existing C# Contracts](HOW_TO_IMPORT_CSHARP_CONTRACTS.md) when you are starting from an existing C# serializer contract.
Copy file name to clipboardExpand all lines: docs/HOW_TO_EXPORT_JSON_SCHEMA.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,13 @@
2
2
3
3
Use `JsonSchema.generate` when you want a JSON Schema document for the JSON wire contract already described by a `Schema<'T>`.
4
4
5
+
This is the authored-schema path. It is separate from JSON Schema import:
6
+
7
+
- export starts from your typed `Schema<'T>`
8
+
- import starts from an external JSON Schema document and returns `Schema<JsonValue>`
9
+
10
+
Keep those two workflows separate when you design your integration boundary.
11
+
5
12
## Export a schema
6
13
7
14
```fsharp
@@ -101,6 +108,8 @@ let value = Json.deserialize codec """{"id":42,"name":"Ada"}"""
101
108
102
109
This path preserves the incoming JSON shape as `JsonValue`. It enforces the supported structural subset and leaves unsupported branch-heavy features on the raw JSON fallback path.
103
110
111
+
This is not a round-trip back into a typed authored schema. It is a receive-side integration boundary for external schema-owned contracts.
112
+
104
113
If you need to know what was enforced, use `JsonSchema.importWithReport`:
0 commit comments