Replaced binary tuple with struct
This commit is contained in:
@ -1,39 +1,27 @@
|
||||
import "@typespec/openapi3";
|
||||
using TypeSpec.OpenAPI;
|
||||
import "@typespec/http";
|
||||
import "./models.tsp";
|
||||
using TypeSpec.Http;
|
||||
using Models;
|
||||
|
||||
enum BinaryOperator {
|
||||
AND,
|
||||
OR,
|
||||
IMPLICATION
|
||||
}
|
||||
|
||||
model ExpressionNot {
|
||||
not: Expression;
|
||||
}
|
||||
|
||||
// TODO tuple type, possible in OpenAPI 3.1, but unsupported in typespec
|
||||
model ExpressionBinary {
|
||||
operator: BinaryOperator;
|
||||
left: Expression;
|
||||
right: Expression;
|
||||
}
|
||||
|
||||
model ExpressionAtomic {
|
||||
atomic: string;
|
||||
}
|
||||
|
||||
@oneOf
|
||||
union Expression {
|
||||
ExpressionNot;
|
||||
ExpressionBinary;
|
||||
ExpressionAtomic;
|
||||
}
|
||||
|
||||
model SimplifyResponse {
|
||||
@service({
|
||||
title: "Simplify Truth Expressions",
|
||||
})
|
||||
namespace Simplify {
|
||||
model SimplifyResponse {
|
||||
before: string;
|
||||
after: string;
|
||||
orderOfOperations: string[];
|
||||
orderOfOperations?: string[] = [];
|
||||
expression: Expression;
|
||||
}
|
||||
|
||||
op simplify(): SimplifyResponse;
|
||||
model SimplifyOptions {
|
||||
lang: "en" | "nb" = "en";
|
||||
simplify: boolean = true;
|
||||
caseSensitive: boolean = false;
|
||||
}
|
||||
|
||||
op simplify(
|
||||
@path exp: string,
|
||||
@query query?: SimplifyOptions
|
||||
): SimplifyResponse;
|
||||
}
|
||||
|
31
spec/models.tsp
Normal file
31
spec/models.tsp
Normal file
@ -0,0 +1,31 @@
|
||||
import "@typespec/openapi3";
|
||||
using TypeSpec.OpenAPI;
|
||||
|
||||
namespace Models;
|
||||
|
||||
enum BinaryOperator {
|
||||
AND,
|
||||
OR,
|
||||
IMPLICATION
|
||||
}
|
||||
|
||||
model ExpressionNot {
|
||||
not: Expression;
|
||||
}
|
||||
|
||||
model ExpressionBinary {
|
||||
left: Expression;
|
||||
operator: BinaryOperator;
|
||||
right: Expression;
|
||||
}
|
||||
|
||||
model ExpressionAtomic {
|
||||
atomic: string;
|
||||
}
|
||||
|
||||
@oneOf
|
||||
union Expression {
|
||||
ExpressionNot;
|
||||
ExpressionBinary;
|
||||
ExpressionAtomic;
|
||||
}
|
@ -1,13 +1,23 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: (title)
|
||||
title: Simplify Truth Expressions
|
||||
version: 0.0.0
|
||||
tags: []
|
||||
paths:
|
||||
/:
|
||||
/{exp}:
|
||||
get:
|
||||
operationId: simplify
|
||||
parameters: []
|
||||
parameters:
|
||||
- name: exp
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- name: query
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
$ref: '#/components/schemas/SimplifyOptions'
|
||||
responses:
|
||||
'200':
|
||||
description: The request has succeeded.
|
||||
@ -17,50 +27,68 @@ paths:
|
||||
$ref: '#/components/schemas/SimplifyResponse'
|
||||
components:
|
||||
schemas:
|
||||
BinaryOperator:
|
||||
Expression:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/Models.ExpressionNot'
|
||||
- $ref: '#/components/schemas/Models.ExpressionBinary'
|
||||
- $ref: '#/components/schemas/Models.ExpressionAtomic'
|
||||
Models.BinaryOperator:
|
||||
type: string
|
||||
enum:
|
||||
- AND
|
||||
- OR
|
||||
- IMPLICATION
|
||||
Expression:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/ExpressionNot'
|
||||
- $ref: '#/components/schemas/ExpressionBinary'
|
||||
- $ref: '#/components/schemas/ExpressionAtomic'
|
||||
ExpressionAtomic:
|
||||
Models.ExpressionAtomic:
|
||||
type: object
|
||||
required:
|
||||
- atomic
|
||||
properties:
|
||||
atomic:
|
||||
type: string
|
||||
ExpressionBinary:
|
||||
Models.ExpressionBinary:
|
||||
type: object
|
||||
required:
|
||||
- operator
|
||||
- left
|
||||
- operator
|
||||
- right
|
||||
properties:
|
||||
operator:
|
||||
$ref: '#/components/schemas/BinaryOperator'
|
||||
left:
|
||||
$ref: '#/components/schemas/Expression'
|
||||
operator:
|
||||
$ref: '#/components/schemas/Models.BinaryOperator'
|
||||
right:
|
||||
$ref: '#/components/schemas/Expression'
|
||||
ExpressionNot:
|
||||
Models.ExpressionNot:
|
||||
type: object
|
||||
required:
|
||||
- not
|
||||
properties:
|
||||
not:
|
||||
$ref: '#/components/schemas/Expression'
|
||||
SimplifyOptions:
|
||||
type: object
|
||||
required:
|
||||
- lang
|
||||
- simplify
|
||||
- caseSensitive
|
||||
properties:
|
||||
lang:
|
||||
type: string
|
||||
enum:
|
||||
- en
|
||||
- nb
|
||||
default: en
|
||||
simplify:
|
||||
type: boolean
|
||||
default: true
|
||||
caseSensitive:
|
||||
type: boolean
|
||||
default: false
|
||||
SimplifyResponse:
|
||||
type: object
|
||||
required:
|
||||
- before
|
||||
- after
|
||||
- orderOfOperations
|
||||
- expression
|
||||
properties:
|
||||
before:
|
||||
@ -71,5 +99,6 @@ components:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
default: []
|
||||
expression:
|
||||
$ref: '#/components/schemas/Expression'
|
||||
|
Reference in New Issue
Block a user