Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release/1.3 #27

Merged
merged 17 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 59 additions & 23 deletions buildHooks/src/genApiSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ const _generateSchemaFile = (opts: { schema: z.ZodObject<any>; schemaId: string;
const jsonSchema: any = zodToJsonSchema(schema);
jsonSchema['$schema'] = 'http://json-schema.org/draft-04/schema#';

const resolvedSchema = resolveRefsInSchema({ ...jsonSchema });
const destFolder = path.join(ctx.paths.project.dir, `docs/api/schemas`);
if (!fs.existsSync(destFolder)) {
fs.mkdirSync(destFolder, { recursive: true });
}
const destPath = path.join(destFolder, `${schemaId}.md`);
// console.log(generate(jsonSchema));
fs.writeFileSync(destPath, generate(jsonSchema, schemaId, sideBarTitle));
fs.writeFileSync(destPath, generate(resolvedSchema, schemaId, sideBarTitle));
};

const generateElementTitle = (
Expand Down Expand Up @@ -135,11 +135,17 @@ const generateSchemaSectionText = (

if (schemaType === 'object') {
if (schema.properties) {
text.push('Properties of the `' + name + '` object:');
text.push('Properties of the' + (name ? ' `' + name + '`' : '') + ' object:');
generatePropertySection(hashtags, schema, subSchemas).forEach((section) => {
text = text.concat(section);
});
}
if (schema.additionalProperties.properties) {
text.push('Properties of the' + (name ? ' `' + name + '`' : '') + ' object:');
generatePropertySection(hashtags, schema.additionalProperties, subSchemas).forEach((section) => {
text = text.concat(section);
});
}
} else if (schemaType === 'array') {
let itemsType = schema.items && schema.items.type;

Expand Down Expand Up @@ -170,7 +176,7 @@ const generateSchemaSectionText = (

if (validationItems.length > 0) {
validationItems.forEach((item: any) => {
text = text.concat(generateSchemaSectionText(hashtags, item.title, false, item, subSchemas));
text = text.concat(generateSchemaSectionText(hashtags, item.title || '', false, item, subSchemas));
});
}
}
Expand Down Expand Up @@ -288,28 +294,58 @@ sidebar_label: ${sidebarLabel}
} else {
text = text.concat(generateSchemaSectionText('#' + hashtags, undefined, false, schema, subSchemaTypes));
}

if (schema.definitions) {
text.push('---');
text.push('# Sub Schemas');
text.push('The schema defines the following additional types:');
Object.keys(schema.definitions).forEach((subSchemaTypeName) => {
text.push('## `' + subSchemaTypeName + '` (' + schema.definitions[subSchemaTypeName].type + ')');
text.push(schema.definitions[subSchemaTypeName].description);
if (schema.definitions[subSchemaTypeName].type === 'object') {
if (schema.definitions[subSchemaTypeName].properties) {
text.push('Properties of the `' + subSchemaTypeName + '` object:');
}
}
generatePropertySection('##', schema.definitions[subSchemaTypeName], subSchemaTypes).forEach((section) => {
text = text.concat(section);
});
});
}

return text
.filter((line) => {
return !!line;
})
.join('\n\n');
};

const resolveRefsInSchema = (schema: any): any => {
const resolveJsonRefs = (schema: any, ref: string): any => {
const pointer = ref.replace(/^#\//, '').split('/');
return pointer.reduce((acc, key) => acc && acc[key], schema);
};

const resolveRefs = (currentSchema: any, depth = 0): any => {
if (currentSchema.$ref) {
const resolvedSchema = resolveJsonRefs(schema, currentSchema.$ref);

return resolveRefs(resolvedSchema, depth);
}

if (currentSchema.type === 'object' && currentSchema.properties) {
const newProperties = {};
Object.keys(currentSchema.properties).forEach((key) => {
newProperties[key] = resolveRefs(currentSchema.properties[key], depth);
});
return { ...currentSchema, properties: newProperties };
}

if (currentSchema.additionalProperties && typeof currentSchema.additionalProperties === 'object') {
const resolvedAdditionalProperties = resolveRefs(currentSchema.additionalProperties, depth);
return { ...currentSchema, additionalProperties: resolvedAdditionalProperties };
}

if (currentSchema.type === 'array' && currentSchema.items) {
if (depth > 0) {
return currentSchema;
}
// depth <= recursion limit for `items` field to avoid circular refs (children)
const resolvedItems = resolveRefs(currentSchema.items, depth + 1);

return { ...currentSchema, items: resolvedItems };
}
if (Array.isArray(currentSchema.anyOf)) {
return {
...currentSchema,
anyOf: currentSchema.anyOf.map((subSchema: any) => {
return resolveRefs(subSchema, depth);
}),
};
}
return currentSchema;
};

return resolveRefs(schema);
};
32 changes: 24 additions & 8 deletions docs/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,15 @@ Example:
npx rnv clean
```

### status
### info

Show current info about the project
Get relevant version info about OS, toolchain and libraries

Provided by: @rnv/engine-core

Example:
```bash
npx rnv status
npx rnv info
```

### config
Expand Down Expand Up @@ -337,7 +337,7 @@ Provided by: @rnv/engine-core


Available Options:
[`git-enabled`](#git-enabled), [`answer`](#answer), [`workspace`](#workspace), [`template`](#template), [`project-name`](#project-name), [`project-template`](#project-template), [`template-version`](#template-version), [`title`](#title), [`app-version`](#app-version), [`id`](#id)
[`git-enabled`](#git-enabled), [`answer`](#answer), [`workspace`](#workspace), [`template`](#template), [`project-name`](#project-name), [`project-template`](#project-template), [`template-version`](#template-version), [`local-template-path`](#local-template-path), [`title`](#title), [`app-version`](#app-version), [`id`](#id)

Example:
```bash
Expand Down Expand Up @@ -483,6 +483,17 @@ Example:
npx rnv app switch
```

### patch reset

Reset applied overrides

Provided by: @rnv/engine-core

Example:
```bash
npx rnv patch reset
```

### target launch

Launch specific target
Expand Down Expand Up @@ -623,7 +634,7 @@ Launch specific ios target
Provided by: @rnv/engine-rn

Depends On:
[`workspace configure`](#workspace-configure)
[`project configure`](#project-configure)


Available Options:
Expand All @@ -641,7 +652,7 @@ List all available targets for specific platform
Provided by: @rnv/engine-rn

Depends On:
[`workspace configure`](#workspace-configure)
[`project configure`](#project-configure)


Available Options:
Expand Down Expand Up @@ -974,7 +985,7 @@ Launch specific ios target
Provided by: @rnv/engine-rn-tvos

Depends On:
[`workspace configure`](#workspace-configure)
[`project configure`](#project-configure)


Available Options:
Expand All @@ -992,7 +1003,7 @@ List all available targets for specific platform
Provided by: @rnv/engine-rn-tvos

Depends On:
[`workspace configure`](#workspace-configure)
[`project configure`](#project-configure)


Available Options:
Expand Down Expand Up @@ -1697,6 +1708,11 @@ Skips auto update of npm dependencies if mismatch found

Type: Flag

### offline
Run without connecting to the internet whenever possible

Type: Flag

### app-config-ID
select specific app Config id

Expand Down
Loading