Skip to content

Commit a72a8e9

Browse files
AllyWkairu-ms
authored andcommitted
refact project
1 parent 3904e69 commit a72a8e9

15 files changed

Lines changed: 173 additions & 169 deletions

File tree

src/typespec-aaz/src/emitter.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import {
2323
import { HttpService, getAllHttpServices, reportIfNoRoutes, getHttpOperation, HttpOperation } from "@typespec/http";
2424
// import { SdkContext, createSdkContext } from "@azure-tools/typespec-client-generator-core";
2525
import {getResourcePath, swaggerResourcePathToResourceId, } from "./utils.js";
26-
import { AAZResourceEmitterSchema, AAZTspPathItem, MutabilityEnum, AAZTspHttpOperation } from "./types.js";
26+
import { AAZResourceEmitterSchema } from "./types.js";
27+
import { TypeSpecPathItem } from "./model/path_item.js"
28+
import { MutabilityEnum } from "./model/_fields.js"
29+
import { CMDHttpOperation } from "./model/operation.js"
2730
import { AAZEmitterOptions, getTracer } from "./lib.js";
2831

2932
export async function $onEmit(context: EmitContext<AAZEmitterOptions>) {
@@ -34,14 +37,9 @@ export async function $onEmit(context: EmitContext<AAZEmitterOptions>) {
3437
path: resolvePath(context.emitterOutputDir, "resources.json"),
3538
content: JSON.stringify(resources, null, 2),
3639
});
37-
} else if (context.options.operation === "retrieve-operation") {
38-
// TODO:
39-
// const sdkContext = createSdkContext(context, "@client-tools/typespec-aaz");
40-
// const emitter = createRetrieveOperationsEmitter(sdkContext);
41-
// await emitter.retrieveOperations();
4240
} else if (context.options.operation === "get-resources-operations") {
4341
const emitter = createGetResourceOperationEmitter(context);
44-
const res = await emitter.getResourcesOperation();
42+
const res = await emitter.getResourcesOperations();
4543
await emitFile(context.program, {
4644
path: resolvePath(context.emitterOutputDir, "resources_operations.json"),
4745
content: JSON.stringify(res, null, 2),
@@ -123,9 +121,9 @@ function createGetResourceOperationEmitter(context: EmitContext<AAZEmitterOption
123121
version: context.options.apiVersion,
124122
}
125123
}) || [];
126-
let schema: AAZTspPathItem = {};
124+
let schema: TypeSpecPathItem = {};
127125

128-
async function getResourcesOperation() {
126+
async function getResourcesOperations() {
129127
tracer.trace("options for createGetResourceOperationEmitter", JSON.stringify(context.options, null, 2));
130128
const services = listServices(context.program);
131129
for (const service of services) {
@@ -149,7 +147,7 @@ function createGetResourceOperationEmitter(context: EmitContext<AAZEmitterOption
149147
return result;
150148
}
151149

152-
return { getResourcesOperation };
150+
return { getResourcesOperations };
153151

154152
function emitResourcesOperations(program: Program, operations: HttpOperation[]) {
155153
for (let rt of result) {
@@ -167,7 +165,7 @@ function createGetResourceOperationEmitter(context: EmitContext<AAZEmitterOption
167165
}
168166
}
169167

170-
function emitResourceOperation(program: Program, httpOperation: HttpOperation, resourceObj: AAZResourceEmitterSchema, schema:AAZTspPathItem){
168+
function emitResourceOperation(program: Program, httpOperation: HttpOperation, resourceObj: AAZResourceEmitterSchema, schema:TypeSpecPathItem){
171169
let { path: fullPath, operation: op, verb, parameters } = httpOperation;
172170
let selected_path = getPathWithoutArg(fullPath).toLocaleLowerCase();
173171
if (selected_path != resourceObj.id) {
@@ -193,7 +191,7 @@ function createGetResourceOperationEmitter(context: EmitContext<AAZEmitterOption
193191
} else{
194192
console.log(" verb not expected: ", verb)
195193
}
196-
let operationOnMutability: AAZTspHttpOperation;
194+
let operationOnMutability: CMDHttpOperation;
197195
for (let mut of mutability){
198196
operationOnMutability = {
199197
operationId: opId,
@@ -244,7 +242,7 @@ function createGetResourceOperationEmitter(context: EmitContext<AAZEmitterOption
244242
return false;
245243
}
246244

247-
function populateOperationOnMutability(program: Program, httpOperation: HttpOperation, operationOnMutability:AAZTspHttpOperation) {
245+
function populateOperationOnMutability(program: Program, httpOperation: HttpOperation, operationOnMutability: CMDHttpOperation) {
248246
operationOnMutability.description = getDoc(program, httpOperation.operation);
249247

250248
const lroMetadata = getLroMetadata(program, httpOperation.operation);
@@ -260,8 +258,6 @@ function createGetResourceOperationEmitter(context: EmitContext<AAZEmitterOption
260258
request: {} as any,
261259
response: [],
262260
}
263-
264-
265261
}
266262

267263
}

src/typespec-aaz/src/lib.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { JSONSchemaType, createTypeSpecLibrary } from "@typespec/compiler";
22

33
export interface AAZEmitterOptions {
4-
"operation": "list-resources" | "retrieve-operation" | "get-resources-operations";
4+
"operation": "list-resources" | "get-resources-operations";
55
"apiVersion"?: string;
66
"resources"?: string[];
77
}
@@ -12,7 +12,7 @@ const EmitterOptionsSchema: JSONSchemaType<AAZEmitterOptions> = {
1212
properties: {
1313
operation: {
1414
type: "string",
15-
enum: ["list-resources", "retrieve-operation", "get-resources-operations"],
15+
enum: ["list-resources", "get-resources-operations"],
1616
},
1717
"apiVersion": {
1818
type: "string",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { CMDSchema } from "./_schema.js"
2+
import { CMDVariantField } from "./_fields.js";
3+
4+
export type CMDRequestJson = {
5+
ref?: string;
6+
schema?: CMDSchema;
7+
}
8+
9+
export type CMDResponseJson = {
10+
var?: CMDVariantField;
11+
schema: CMDSchema;
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
export type CMDVariantField = {
3+
value: string;
4+
format: '[$@][a-zA-Z0-9_\[\]\{\}\.]+'
5+
}
6+
7+
export enum MutabilityEnum {
8+
Create = "create",
9+
Read = "read",
10+
Update = "update",
11+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { CMDSchema } from "./_schema.js";
2+
import { CMDHttpRequestBody } from "./_http_request_body.js";
3+
import { CMDHttpResponseBody } from "./_http_response_body.js";
4+
import { CMDVariantField } from "./_fields.js";
5+
6+
export type CMDHttpAction = {
7+
path: string;
8+
request?: CMDHttpRequest;
9+
response?: CMDHttpResponse[];
10+
}
11+
12+
export type CMDHttpRequest = {
13+
method: "get" | "put" | "post" | "delete" | "options" | "head" | "patch";
14+
path: CMDHttpRequestArgs;
15+
query: CMDHttpRequestArgs;
16+
header: CMDHttpRequestHeader;
17+
body: CMDHttpRequestBody;
18+
}
19+
20+
export type CMDHttpResponse = {
21+
statusCode?: number[];
22+
isError?: boolean;
23+
description?: string;
24+
header?: CMDHttpResponseHeader;
25+
body?: CMDHttpResponseBody;
26+
}
27+
28+
export interface CMDHttpRequestArgs {
29+
params: CMDSchema[];
30+
consts: CMDSchema[];
31+
}
32+
33+
export interface CMDHttpRequestHeader extends CMDHttpRequestArgs {
34+
clientRequestId?: string;
35+
}
36+
37+
export type CMDHttpResponseHeader = {
38+
items: CMDHttpResponseHeaderItem[]
39+
}
40+
41+
export type CMDHttpResponseHeaderItem = {
42+
name: string;
43+
var?: CMDVariantField;
44+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { CMDRequestJson } from "./_content.js"
2+
3+
export type CMDHttpRequestBody = {
4+
json?: CMDRequestJson;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { CMDResponseJson } from "./_content.js"
2+
3+
export type CMDHttpResponseBody = {
4+
json?: CMDResponseJson;
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { CMDVariantField } from "./_fields.js"
2+
3+
export interface CMDSchemaBase {
4+
readOnly?: boolean;
5+
frozen?: boolean; // python set?
6+
const?: boolean;
7+
default?: "string" | "number" | "integer" | "boolean" | "array" | "object";
8+
nullable?: boolean;
9+
}
10+
11+
export interface CMDSchema extends CMDSchemaBase {
12+
name: string;
13+
arg?: CMDVariantField;
14+
required?: boolean;
15+
description?: string;
16+
skipUrlEncoding?: boolean;
17+
secret?: boolean;
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
export enum CMDBuildInVariants {
3+
Instance = "$Instance",
4+
EndpointInstance = "$EndpointInstance",
5+
Subresource = "$Subresource",
6+
Endpoint = "$Endpoint",
7+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { CMDVariantField } from "./_fields.js"
2+
import { CMDHttpAction } from "./_http.js"
3+
4+
export type TypeSpecOperation = {
5+
operationId?: string;
6+
isPageable?: boolean;
7+
read?: CMDHttpOperation;
8+
create?: CMDHttpOperation;
9+
update?: CMDHttpOperation;
10+
};
11+
12+
export interface CMDHttpOperation {
13+
when?: CMDVariantField[];
14+
longRunning?:CMDHttpOperationLongRunning;
15+
// required
16+
operationId: string;
17+
description?: string;
18+
// required
19+
http: CMDHttpAction;
20+
}
21+
22+
23+
export type CMDHttpOperationLongRunning = {
24+
// "azure-async-operation" | "location" | "original-uri"
25+
finalStateVia?: string;
26+
}

0 commit comments

Comments
 (0)