diff --git a/OPENAPI_DOC.yml b/OPENAPI_DOC.yml index e44686b9..357790ca 100644 --- a/OPENAPI_DOC.yml +++ b/OPENAPI_DOC.yml @@ -7562,6 +7562,8 @@ paths: - type: boolean - type: "null" responses: + "204": + description: No Content "200": description: OK content: @@ -17769,13 +17771,13 @@ components: properties: created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" name: anyOf: @@ -17806,13 +17808,13 @@ components: properties: created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" purchase_order_number: anyOf: @@ -17824,7 +17826,7 @@ components: - type: string supplier_details: anyOf: - - type: object + - {} - type: "null" purchase_date: anyOf: @@ -17859,13 +17861,13 @@ components: properties: created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" name: anyOf: @@ -17893,6 +17895,12 @@ components: anyOf: - type: "null" - type: string + asset_count: + anyOf: + - type: integer + format: Int64 + - type: "null" + readOnly: true id: anyOf: - type: "null" @@ -17902,13 +17910,13 @@ components: properties: created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" identifier: anyOf: @@ -17920,7 +17928,7 @@ components: - type: string other_data: anyOf: - - type: object + - {} - type: "null" barcode: anyOf: @@ -17932,7 +17940,7 @@ components: - type: string client_ids: anyOf: - - type: object + - {} - type: "null" map_id: anyOf: @@ -18091,6 +18099,7 @@ components: anyOf: - type: "null" - type: string + format: email department: anyOf: - type: "null" @@ -18141,7 +18150,7 @@ components: - type: string extension_data: anyOf: - - type: object + - {} - type: "null" history: anyOf: @@ -18149,6 +18158,27 @@ components: - type: array items: $ref: '#/components/schemas/PlaceOS.Model.Booking.History' + email_digest: + anyOf: + - type: "null" + - type: string + readOnly: true + booked_by_id: + anyOf: + - type: "null" + - type: string + readOnly: true + booked_by_email_digest: + anyOf: + - type: "null" + - type: string + readOnly: true + created: + anyOf: + - type: integer + format: Int64 + - type: "null" + readOnly: true parent_id: anyOf: - type: integer @@ -18166,12 +18196,40 @@ components: format: Int64 - type: "null" description: provided when this booking is an instance of recurring booking - attendees: + linked_event: + anyOf: + - type: "null" + - $ref: '#/components/schemas/PlaceOS.Model.EventMetadata' + readOnly: true + linked_bookings: anyOf: - type: "null" - type: array items: - $ref: '#/components/schemas/PlaceCalendar.Event.Attendee' + $ref: '#/components/schemas/PlaceOS.Model.Booking' + readOnly: true + linked_parent_booking: + anyOf: + - type: "null" + - $ref: '#/components/schemas/PlaceOS.Model.Booking' + readOnly: true + attendees: + anyOf: + - anyOf: + - type: "null" + - type: array + items: + $ref: '#/components/schemas/PlaceCalendar.Event.Attendee' + - anyOf: + - type: "null" + - type: array + items: + $ref: '#/components/schemas/PlaceOS.Model.Attendee' + current_state: + anyOf: + - $ref: '#/components/schemas/PlaceOS.Model.Booking.State' + - type: "null" + readOnly: true asset_ids: anyOf: - type: "null" @@ -18186,12 +18244,20 @@ components: type: string induction: anyOf: - - $ref: '#/components/schemas/PlaceOS.Model.Booking.Induction' + - enum: + - tentative + - accepted + - declined + type: string - type: "null" description: The induction status of the booking. Defaults to TENTATIVE. permission: anyOf: - - $ref: '#/components/schemas/PlaceOS.Model.Booking.Permission' + - enum: + - private + - open + - public + type: string - type: "null" description: The permission level for the booking. Defaults to private. If set to private, attendees must be invited.If set to open, users in @@ -18199,7 +18265,12 @@ components: to join. recurrence_type: anyOf: - - $ref: '#/components/schemas/PlaceOS.Model.Booking.Recurrence' + - enum: + - none + - daily + - weekly + - monthly + type: string - type: "null" description: Is this a recurring booking. This field defines the type of recurrence @@ -18239,6 +18310,13 @@ components: - type: integer format: Int64 - type: "null" + guests: + anyOf: + - type: "null" + - type: array + items: + $ref: '#/components/schemas/PlaceOS.Model.Guest' + readOnly: true id: anyOf: - type: integer @@ -18246,13 +18324,13 @@ components: - type: "null" created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" PlaceOS.Model.Guest: type: object @@ -18261,6 +18339,7 @@ components: anyOf: - type: "null" - type: string + format: email name: anyOf: - type: "null" @@ -18299,8 +18378,33 @@ components: - type: string extension_data: anyOf: - - type: object + - {} - type: "null" + checked_in: + anyOf: + - type: boolean + - type: "null" + readOnly: true + visit_expected: + anyOf: + - type: boolean + - type: "null" + readOnly: true + booking: + anyOf: + - type: "null" + - $ref: '#/components/schemas/PlaceOS.Model.Booking' + readOnly: true + event: + anyOf: + - type: "null" + - $ref: '#/components/schemas/PlaceCalendar.Event' + readOnly: true + event_metadata: + anyOf: + - type: "null" + - type: object + readOnly: true tenant_id: anyOf: - type: integer @@ -18313,13 +18417,13 @@ components: - type: "null" created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" PlaceCalendar.Event.Attendee: type: object @@ -18350,7 +18454,7 @@ components: - type: "null" extension_data: anyOf: - - type: object + - {} - type: "null" preferred_name: anyOf: @@ -18453,13 +18557,13 @@ components: - type: "null" created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" PlaceCalendar.Calendar: type: object @@ -18605,8 +18709,8 @@ components: format: Int64 event_end: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" id: anyOf: @@ -18737,12 +18841,19 @@ components: - type: "null" extension_data: anyOf: - - type: object + - {} - type: "null" recurring_master_id: anyOf: - type: "null" - type: string + linked_bookings: + anyOf: + - type: "null" + - type: array + items: + $ref: '#/components/schemas/PlaceOS.Model.Booking' + readOnly: true setup_time: anyOf: - type: integer @@ -18804,11 +18915,11 @@ components: type: string diff: anyOf: - - type: object + - {} - type: "null" snapshot: anyOf: - - type: object + - {} - type: "null" user_id: anyOf: @@ -18820,12 +18931,12 @@ components: - type: string context: anyOf: - - type: object + - {} - type: "null" created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" PlaceOS.Model.EventMetadata: type: object @@ -18874,7 +18985,7 @@ components: - type: "null" ext_data: anyOf: - - type: object + - {} - type: "null" setup_time: anyOf: @@ -18896,7 +19007,11 @@ components: - type: string permission: anyOf: - - $ref: '#/components/schemas/PlaceOS.Model.EventMetadata.Permission' + - enum: + - private + - open + - public + type: string - type: "null" description: The permission level for the event. Defaults to private. If set to private, attendees must be invited.If set to open, users in the @@ -18907,6 +19022,13 @@ components: - type: integer format: Int64 - type: "null" + linked_bookings: + anyOf: + - type: "null" + - type: array + items: + $ref: '#/components/schemas/PlaceOS.Model.Booking' + readOnly: true id: anyOf: - type: integer @@ -18914,13 +19036,13 @@ components: - type: "null" created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" PlaceCalendar.Group: type: object @@ -18965,8 +19087,7 @@ components: anyOf: - type: "null" - type: object - additionalProperties: - type: object + additionalProperties: {} required: - id - email @@ -19257,8 +19378,7 @@ components: anyOf: - type: "null" - type: object - additionalProperties: - type: object + additionalProperties: {} Staff.Busy: type: object properties: @@ -19295,7 +19415,18 @@ components: - type: string trigger: anyOf: - - $ref: '#/components/schemas/PlaceOS.Model.Survey.TriggerType' + - enum: + - none + - reserved + - checkedin + - checkedout + - noshow + - rejected + - cancelled + - ended + - visitor_checkedin + - visitor_checkedout + type: string - type: "null" description: 'Triggers on booking states: RESERVED, CHECKEDIN, CHECKEDOUT, REJECTED, CANCELLED, VISITOR_CHECKEDIN, VISITOR_CHECKEDOUT' @@ -19324,13 +19455,13 @@ components: - type: "null" created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" PlaceOS.Model.Survey.Answer: type: object @@ -19341,7 +19472,7 @@ components: - type: string answer_json: anyOf: - - type: object + - {} - type: "null" question_id: anyOf: @@ -19360,13 +19491,13 @@ components: - type: "null" created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" PlaceOS.Model.Survey.Invitation: type: object @@ -19395,13 +19526,13 @@ components: - type: "null" created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" PlaceOS.Model.Survey.Question: type: object @@ -19420,7 +19551,7 @@ components: - type: string options: anyOf: - - type: object + - {} - type: "null" required: anyOf: @@ -19428,7 +19559,7 @@ components: - type: "null" choices: anyOf: - - type: object + - {} - type: "null" max_rating: anyOf: @@ -19451,6 +19582,11 @@ components: - type: integer format: Int64 - type: "null" + deleted: + anyOf: + - type: boolean + - type: "null" + readOnly: true authority_id: anyOf: - type: "null" @@ -19462,13 +19598,13 @@ components: - type: "null" created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" Office365.ChatMessageList: type: object @@ -19627,11 +19763,11 @@ components: - type: string credentials: anyOf: - - type: object + - {} - type: "null" booking_limits: anyOf: - - type: object + - {} - type: "null" booking_range: anyOf: @@ -19660,8 +19796,8 @@ components: type: object properties: created_at: - type: string - format: date-time + type: integer + format: Int64 name: type: string nickname: @@ -19744,8 +19880,8 @@ components: format: Int64 last_login: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" work_preferences: type: array @@ -19897,31 +20033,29 @@ components: required: - state - time - PlaceOS.Model.Booking.Permission: - type: string - enum: - - private - - open - - public - PlaceOS.Model.Booking.Recurrence: + PlaceOS.Model.Booking.State: type: string enum: - - none - - daily - - weekly - - monthly + - reserved + - checked_in + - checked_out + - no_show + - rejected + - cancelled + - ended + - unknown PlaceOS.Model.ControlSystem: type: object properties: created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" name: anyOf: @@ -19989,7 +20123,7 @@ components: type: string timezone: anyOf: - - type: object + - type: string - type: "null" support_url: anyOf: @@ -20037,7 +20171,12 @@ components: type: string orientation: anyOf: - - $ref: '#/components/schemas/PlaceOS.Model.Playlist.Orientation' + - enum: + - unspecified + - landscape + - portrait + - square + type: string - type: "null" sign_height: anyOf: @@ -20061,8 +20200,8 @@ components: - type: "null" signage_last_seen: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" playlist_item_id: anyOf: @@ -20072,8 +20211,7 @@ components: anyOf: - type: "null" - type: object - additionalProperties: - type: object + additionalProperties: {} remove_zones: anyOf: - type: "null" @@ -20294,13 +20432,13 @@ components: properties: created_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" updated_at: anyOf: - - type: string - format: date-time + - type: integer + format: Int64 - type: "null" name: anyOf: @@ -20348,7 +20486,7 @@ components: - type: string timezone: anyOf: - - type: object + - type: string - type: "null" triggers: anyOf: @@ -20403,8 +20541,7 @@ components: type: string description: type: string - details: - type: object + details: {} parent_id: anyOf: - type: "null" @@ -20522,19 +20659,6 @@ components: - all_day - private description: a meeting in the space's calendar - PlaceOS.Model.Survey.TriggerType: - type: string - enum: - - none - - reserved - - checkedin - - checkedout - - noshow - - rejected - - cancelled - - ended - - visitor_checkedin - - visitor_checkedout PlaceOS.Model.Survey.Page: type: object properties: @@ -20745,24 +20869,6 @@ components: required: - day_of_week - blocks - PlaceOS.Model.Booking.State: - type: string - enum: - - reserved - - checked_in - - checked_out - - no_show - - rejected - - cancelled - - ended - - unknown - PlaceOS.Model.Playlist.Orientation: - type: string - enum: - - unspecified - - landscape - - portrait - - square PlaceCalendar.AvailabilityStatus: type: string enum: @@ -20986,8 +21092,7 @@ components: : type: array Hash-oString-nJSON.Any-c: type: object - additionalProperties: - type: object + additionalProperties: {} NamedTuple-ocan_edit-u00003A-u000020Bool-c: type: object properties: @@ -20999,8 +21104,7 @@ components: anyOf: - $ref: '#/components/schemas/PlaceCalendar.Event.Attendee' - $ref: '#/components/schemas/PlaceOS.Model.Attendee' - JSON.Any: - type: object + JSON.Any: {} -oPlaceCalendar.Event-pNil-c: anyOf: - type: "null" diff --git a/shard.lock b/shard.lock index 7db58548..ec72b51b 100644 --- a/shard.lock +++ b/shard.lock @@ -103,7 +103,7 @@ shards: json-schema: git: https://github.com/spider-gazelle/json-schema.git - version: 2.1.2 + version: 2.1.3 jwt: git: https://github.com/crystal-community/jwt.git @@ -151,7 +151,7 @@ shards: placeos-models: git: https://github.com/placeos/models.git - version: 9.123.6 + version: 9.123.7 pool: git: https://github.com/ysbaddaden/pool.git diff --git a/shard.yml b/shard.yml index 7100d66b..dcfbc96a 100644 --- a/shard.yml +++ b/shard.yml @@ -10,8 +10,14 @@ dependencies: github: spider-gazelle/action-controller version: ">= 5.1" + # OpenAPI schema generation + json-schema: + github: spider-gazelle/json-schema + version: ">= 2.1.3" + placeos-models: github: placeos/models + version: ">= 9.123.7" placeos-log-backend: github: place-labs/log-backend diff --git a/spec/controllers/calendars_spec.cr b/spec/controllers/calendars_spec.cr index 4a17d4dd..0e4811f5 100644 --- a/spec/controllers/calendars_spec.cr +++ b/spec/controllers/calendars_spec.cr @@ -15,6 +15,20 @@ describe Calendars do end describe "#availability" do + it "returns a documented empty response when there are no calendars to check" do + start = Time.utc(2021, 3, 15, 10).to_unix + finish = Time.utc(2021, 3, 15, 11).to_unix + route = "#{CALENDARS_BASE}/availability" + response = client.get("#{route}?period_start=#{start}&period_end=#{finish}", headers: headers) + response.status_code.should eq(204) + response.body.should be_empty + + document = AC::OpenAPI.generate_open_api_docs({} of String => AC::OpenAPI::KlassDoc, title: "Staff API", version: "v1") + responses = document[:paths][route].get.not_nil!.responses + responses["204"].content.should be_nil + responses["200"].content.not_nil!["application/json"].schema["type"].should eq("array") + end + # a room's resource calendar passed via `calendars` (not `system_ids`) resolves to its # system from our own registry -- WITHOUT a calendar-provider round trip. The calendars # list endpoint is deliberately not stubbed: if it were called, WebMock would raise. diff --git a/spec/controllers/events_spec.cr b/spec/controllers/events_spec.cr index 05d4a6fc..cef7de1b 100644 --- a/spec/controllers/events_spec.cr +++ b/spec/controllers/events_spec.cr @@ -40,15 +40,22 @@ describe Events, tags: ["event"] do tenant = get_tenant - EventMetadatasHelper.create_event(tenant.id, ext_data: JSON.parse({"colour": "blue"}.to_json)) + matching = EventMetadatasHelper.create_event( + tenant.id, + host: "red@example.com", + ext_data: JSON.parse(%({"colour":"blue"})), + ) EventMetadatasHelper.create_event(tenant.id) - EventMetadatasHelper.create_event(tenant.id, ext_data: JSON.parse({"colour": "red"}.to_json)) + EventMetadatasHelper.create_event(tenant.id, ext_data: JSON.parse(%({"colour":"red"}))) field_name = "colour" value = "blue" + response = client.get("#{EVENTS_BASE}/extension_metadata?field_name=#{field_name}&value=#{value}", headers: headers) + response.status_code.should eq 200 - body = JSON.parse(client.get("#{EVENTS_BASE}/extension_metadata?field_name=#{field_name}&value=#{value}", headers: headers).body) - body.to_s.includes?("red").should be_false + events = JSON.parse(response.body).as_a + events.map(&.["event_id"].as_s).should eq [matching.event_id] + events.first["ext_data"][field_name].as_s.should eq value end it "#index should return a list of events with metadata of master event if event in list is an occurrence" do diff --git a/src/controllers/calendars.cr b/src/controllers/calendars.cr index 3757a5e1..07af3031 100644 --- a/src/controllers/calendars.cr +++ b/src/controllers/calendars.cr @@ -76,7 +76,7 @@ class Calendars < Application # Find the rooms or people that are free for a whole time period. @[AC::MCP(ui: "spaces/card.html")] - @[AC::Route::GET("/availability")] + @[AC::Route::GET("/availability", status: {Nil => HTTP::Status::NO_CONTENT})] def availability( @[AC::Param::Info(description: "search period start as a unix epoch in seconds", example: "1661725146")] period_start : Int64, @@ -84,7 +84,7 @@ class Calendars < Application period_end : Int64, @[AC::Param::Info(description: "a comma separated list of calendar ids (email addresses) to include; for room resource calendars prefer `system_ids`", example: "user@org.com,room2@resource.org.com")] calendars : String? = nil, - ) : Array(Availability) + ) : Array(Availability)? # Grab the system emails candidates = matching_calendars.transform_keys &.downcase candidate_calendars = candidates.keys @@ -95,7 +95,7 @@ class Calendars < Application all_calendars.concat(candidate_calendars) calendars = all_calendars.to_a - render :no_content, json: [] of Availability if calendars.empty? + return if calendars.empty? calendars = free_calendars(calendars, Time.unix(period_start), Time.unix(period_end)) calendars.map { |email|