-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.rs
56 lines (49 loc) · 1.99 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH.
// All rights reserved.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.
use jsonptr::Pointer;
use std::env;
use std::fs::File;
use std::path::PathBuf;
use typify::{TypeSpace, TypeSpaceSettings};
fn main() -> std::io::Result<()> {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let mut parsed_content: serde_json::Value =
serde_json::from_reader(File::open("./endpoint_manifest_schema.json").unwrap()).unwrap();
// Patch schema for https://github.com/oxidecomputer/typify/issues/531
// We can get rid of this once the issue in typify is solved.
Pointer::from_static(
"/properties/services/items/properties/handlers/items/properties/input/default",
)
.delete(&mut parsed_content);
Pointer::from_static(
"/properties/services/items/properties/handlers/items/properties/input/examples",
)
.delete(&mut parsed_content);
Pointer::from_static(
"/properties/services/items/properties/handlers/items/properties/output/default",
)
.delete(&mut parsed_content);
Pointer::from_static(
"/properties/services/items/properties/handlers/items/properties/output/examples",
)
.delete(&mut parsed_content);
// Instantiate type space and run code-generation
let mut type_space =
TypeSpace::new(TypeSpaceSettings::default().with_derive("Clone".to_owned()));
type_space
.add_root_schema(serde_json::from_value(parsed_content).unwrap())
.unwrap();
let contents = format!(
"{}\n{}",
"use serde::{Deserialize, Serialize};",
prettyplease::unparse(&syn::parse2::<syn::File>(type_space.to_stream()).unwrap())
);
std::fs::write(out_dir.join("endpoint_manifest.rs"), contents)
}