Completely override response json-ld #context - symfony

Is it possible to override completely the #context of an api-platform ld+json response ?
(I had to replace the localhost urls with <base-api-url>, otherwise the question was marked as spam)
I have this PHP Dto :
#[ApiResource(
shortName: 'Account',
types: [
'https://www.w3.org/ns/activitystreams',
],
operations: [
new Get(
uriTemplate: '/accounts/{id}',
uriVariables: [
'id' => new Link(
fromProperty: 'id',
fromClass: Account::class,
)
],
controller: GetPersonController::class,
normalizationContext: [
'groups' => ['activitypub'],
'jsonld_embed_context' => true
],
provider: AccountStateProvider::class
)
]
)]
class Person
{
#[ApiProperty(identifier: true)]
#[Groups(['activitypub'])]
public string $id;
#[Groups(['activitypub'])]
public string $type = "Person";
#[Groups(['activitypub'])]
public string $following;
[...]
And the response is :
{
"#context": {
"#vocab": "<base-api-url>docs.jsonld#",
"hydra": "http://www.w3.org/ns/hydra/core#",
"id": "Account/id",
"type": "Account/type",
"following": "Account/following",
"followers": "Account/followers",
"inbox": "Account/inbox",
"outbox": "Account/outbox",
"name": "Account/name",
"preferredUsername": "Account/preferredUsername",
"summary": "Account/summary",
"url": "Account/url",
"published": "Account/published"
},
"#id": "/accounts/0185f9ad-5602-7aef-bac3-1a4d1b32a409",
"#type": "https://www.w3.org/ns/activitystreams",
"id": "<base-api-url>accounts/0185f9ad-5602-7aef-bac3-1a4d1b32a409",
"type": "Person",
"following": "<base-api-url>accounts/0185f9ad-5602-7aef-bac3-1a4d1b32a409/followings",
"followers": "<base-api-url>accounts/0185f9ad-5602-7aef-bac3-1a4d1b32a409/followers",
"inbox": "<base-api-url>accounts/0185f9ad-5602-7aef-bac3-1a4d1b32a409/inbox",
"outbox": "<base-api-url>accounts/0185f9ad-5602-7aef-bac3-1a4d1b32a409/outbox",
"name": "Test User",
"preferredUsername": "testuser",
"summary": "",
"url": "https://localhost/#testuser",
"published": "2023-01-28T18:39:24+00:00"
}
What I need is :
{
"#context": [
"https://www.w3.org/ns/activitystreams"
],
"id": "<base-api-url>accounts/0185f9ad-5602-7aef-bac3-1a4d1b32a409",
"type": "Person",
"following": "<base-api-url>accounts/0185f9ad-5602-7aef-bac3-1a4d1b32a409/followings",
"followers": "<base-api-url>accounts/0185f9ad-5602-7aef-bac3-1a4d1b32a409/followers",
"inbox": "<base-api-url>accounts/0185f9ad-5602-7aef-bac3-1a4d1b32a409/inbox",
"outbox": "<base-api-url>accounts/0185f9ad-5602-7aef-bac3-1a4d1b32a409/outbox",
"name": "Test User",
"preferredUsername": "testuser",
"summary": "",
"url": "https://localhost/#testuser",
"published": "2023-01-28T18:39:24+00:00"
}

Related

TypeError: Cannot read property 'kind' of undefined

I am trying to migrate my v3 strapi app to v4 on my local machine with the local database. I am trying to perform code migration. Initially I have changed the config files following the documentation of strapi v4. I have used codemods to change the folder structure and to update the routes, controllers and services.
Now when I am trying to run my strapi application I am getting this error and the app build is breaking.
These are my route, controller, services and schema.json file
route:
'use strict';
/**
* blog router
*/
const { createCoreRouter } = require('#strapi/strapi').factories;
module.exports = createCoreRouter('api::blog.blog');
Controller:
'use strict';
/**
* blog controller
*/
const { createCoreController } = require('#strapi/strapi').factories;
module.exports = createCoreController('api::blog.blog');
service:
'use strict';
/**
* blog service
*/
const { createCoreService } = require('#strapi/strapi').factories;
module.exports = createCoreService('api::blog.blog');
schema.json:
{
"kind": "collectionType",
"collectionName": "blogs",
"info": {
"singularName": "blog",
"pluralName": "blogs",
"displayName": "Blog",
"name": "blog"
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"insightImage": {
"type": "media",
"allowedTypes": [
"images",
"files",
"videos"
],
"multiple": false,
"required": false
},
"insightTitle": {
"type": "string"
},
"insightDescription": {
"type": "text"
},
"insightContent": {
"type": "richtext"
},
"slug": {
"type": "string",
"unique": true
},
"categories": {
"type": "relation",
"relation": "manyToMany",
"target": "api::category.category",
"mappedBy": "blogs"
},
"insightDate": {
"type": "date"
},
"views": {
"type": "integer",
"default": 0
},
"featured": {
"type": "boolean"
},
"frontImage": {
"type": "boolean"
},
"insightsMetaData": {
"type": "component",
"repeatable": false,
"component": "meta.metadata"
},
"industry": {
"type": "relation",
"relation": "manyToOne",
"target": "api::industry.industry",
"inversedBy": "blogs"
},
"solution": {
"type": "relation",
"relation": "manyToOne",
"target": "api::solution.solution",
"inversedBy": "blogs"
},
"type": {
"type": "relation",
"relation": "manyToOne",
"target": "api::type.type",
"inversedBy": "blogs"
},
"featured_topics": {
"type": "relation",
"relation": "manyToMany",
"target": "api::featured-topic.featured-topic",
"inversedBy": "blogs"
},
"formTitle": {
"type": "string"
},
"formId": {
"type": "string"
},
"author": {
"type": "relation",
"relation": "manyToOne",
"target": "api::author.author",
"inversedBy": "blogs"
},
"enableGated": {
"type": "boolean"
},
"insightBannerImage": {
"type": "media",
"allowedTypes": [
"images",
"files",
"videos"
],
"multiple": false,
"required": false
},
"breakTitleText": {
"type": "boolean",
"default": false
}
}
}

How can I create a Pydantic Model for my FastAPI endpoint when my JSON is something like this?

{
'events': [
{
'type': 'message',
'replyToken': '0bc647fc5282423cde13fffbc947a8',
'source': {
'userId': 'U996ed69353d3c962ee17b33d9af3e2',
'type': 'user'
},
'timestamp': 161185209914,
'mode': 'active',
'message': {
'type': 'text',
'id': '1346188304367',
'text': ' hello'
}
}
],
'destination': 'Uf44eb3ba6c4b87adbfaa4a517e'
}
this is the json from the webhook I'm using
it's contained like this, how can I write a Pytantic model for it?
This should work fine with the request body you given above.
from pydantic import BaseModel
from typing import List
class Source(BaseModel):
userId: str
type: str
class Message(BaseModel):
type: str
id: str
text: str
class Event(BaseModel):
type: str
replyToken: str
source: Source
timestamp: int
mode: str
message: Message
class Webhook(BaseModel):
events: List[Event]
destination: str
Here is the OpenAPI schema for Webhook model.
{
"title": "Webhook",
"type": "object",
"properties": {
"events": {
"title": "Events",
"type": "array",
"items": {
"$ref": "#/definitions/Event"
}
},
"destination": {
"title": "Destination",
"type": "string"
}
},
"required": [
"events",
"destination"
],
"definitions": {
"Source": {
"title": "Source",
"type": "object",
"properties": {
"userId": {
"title": "Userid",
"type": "string"
},
"type": {
"title": "Type",
"type": "string"
}
},
"required": [
"userId",
"type"
]
},
"Message": {
"title": "Message",
"type": "object",
"properties": {
"type": {
"title": "Type",
"type": "string"
},
"id": {
"title": "Id",
"type": "string"
},
"text": {
"title": "Text",
"type": "string"
}
},
"required": [
"type",
"id",
"text"
]
},
"Event": {
"title": "Event",
"type": "object",
"properties": {
"type": {
"title": "Type",
"type": "string"
},
"replyToken": {
"title": "Replytoken",
"type": "string"
},
"source": {
"$ref": "#/definitions/Source"
},
"timestamp": {
"title": "Timestamp",
"type": "integer"
},
"mode": {
"title": "Mode",
"type": "string"
},
"message": {
"$ref": "#/definitions/Message"
}
},
"required": [
"type",
"replyToken",
"source",
"timestamp",
"mode",
"message"
]
}
}
}

Write r GET query from data provided

I have JSON data about R request that i need to write with necessary url, access token, parameters and other things, which must be included in httr query. I got it from getpostman item. Here it is:
{
"name": "GET /tablesbyquery",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "hnjP4YUF-woR0jhUyJIByeOI_q8jF99jK5WlQ", #fake for example
"type": "string"
}
]
},
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://somesource.os-pub.com/tables/tablesbyquery?timePeriod=actual&sort=utdDate,asc&query=&isNotEmptyStatus=false&size=20&page=0&providerId=",
"protocol": "http",
"host": [
"somesource",
"os-pub",
"com"
],
"path": [
"tables",
"tablesbyquery"
],
"query": [
{
"key": "timePeriod",
"value": "actual"
},
{
"key": "sort",
"value": "utdDate,asc"
},
{
"key": "query",
"value": ""
},
{
"key": "isNotEmptyStatus",
"value": "false"
},
{
"key": "size",
"value": "20"
},
{
"key": "page",
"value": "0"
},
{
"key": "providerId",
"value": ""
}
]
}
},
"response": []
}
I need to write R request query to GET necessary data. How it should look like? Im new in url and i have written this part:
url <- "http://somesource.os-pub.com/tables/tablesbyquery?timePeriod=actual&sort=utdDate,asc&query=&isNotEmptyStatus=false&size=20&page=0&providerId="
access_token <- "hnjP4YUF-woR0jhUyJIByeOI_q8jF99jK5WlQ"
res <- GET(url, access_token)
content(res, "parsed")
But it doesn't work.

How to get the register device name from OKTA API

I have a requirement to display the OKTA register device name on the screen like the OKTA does for you.
In the picture above it display (Pixel 2 XL) where is the OKTA API to get the register device name
I am referring to OKTA dev API but didn't found anywhere
https://developer.okta.com/docs/reference/api/factors/
Any idea where can I find ???
Once you have the userid you can call the factors list API to get the enrolled MFA factors for the user.
Which will get you back a body like:
[
{
"id": "opffxq5v54xO5kdsa0x6",
"factorType": "push",
"provider": "OKTA",
"vendorName": "OKTA",
"status": "ACTIVE",
"created": "2020-05-07T20:49:49.000Z",
"lastUpdated": "2020-05-20T13:33:58.000Z",
"profile": {
"credentialId": "test#test.com",
"deviceType": "SmartPhone_Android",
"keys": [
{
"kty": "RSA",
"use": "sig",
"kid": "default",
"e": "AQAB",
"n": "j_rlzlG07lZy_TegQPjllleeaGxxDsrtFNaoQHhDowV1z54okXdDobyJo5B9rcCkP7-i0EniNdaCFDj8xugG7WSmcDRzr46AujT7nFVPI5Z7EZE9IaLdYLP0Hg0nRaC3qhHPdv8JGszle8t0Fej1eR-AqT1mrsNUM3-k44_Axj47xhAkIPoxCjyvvA8W1FWKQbECe_y-HtlcLksJlW03WDt_bCdKwx2uVqca1yiEIF3HwhHtpK1dfwosjyEvfpTtsUWtKJVsJiksLajDhu9dGN3JcOT9unsLbWcyWc-kfQ9_oiaMikZCvtbONGSgVjtBttc95-8CHMw-tpA4HCRlcw"
}
],
"name": "Pixel 4 XL",
"platform": "ANDROID",
"version": "29"
},
"_links": {
"self": {
"href": "https://<yourtenant>.oktapreview.com/api/v1/users/00u9ivp5ft7EHNTRW0x6/factors/opffxq5v54xO5kdsa0x6",
"hints": {
"allow": [
"GET",
"DELETE"
]
}
},
"verify": {
"href": "https://<yourtenant>.oktapreview.com/api/v1/users/00u9ivp5ft7EHNTRW0x6/factors/opffxq5v54xO5kdsa0x6/verify",
"hints": {
"allow": [
"POST"
]
}
},
"user": {
"href": "https://<yourtenant>.oktapreview.com/api/v1/users/00u9ivp5ft7EHNTRW0x6",
"hints": {
"allow": [
"GET"
]
}
}
}
},
{
"id": "ostgppjgvFiLfBv850x6",
"factorType": "token:software:totp",
"provider": "OKTA",
"vendorName": "OKTA",
"status": "ACTIVE",
"created": "2020-05-20T13:33:58.000Z",
"lastUpdated": "2020-05-20T13:33:58.000Z",
"profile": {
"credentialId": "test#test.com"
},
"_links": {
"self": {
"href": "https://<yourtenant>.oktapreview.com/api/v1/users/00u9ivp5ft7EHNTRW0x6/factors/ostgppjgvFiLfBv850x6",
"hints": {
"allow": [
"GET",
"DELETE"
]
}
},
"verify": {
"href": "https://<yourtenant>.oktapreview.com/api/v1/users/00u9ivp5ft7EHNTRW0x6/factors/ostgppjgvFiLfBv850x6/verify",
"hints": {
"allow": [
"POST"
]
}
},
"user": {
"href": "https://<yourtenant>.oktapreview.com/api/v1/users/00u9ivp5ft7EHNTRW0x6",
"hints": {
"allow": [
"GET"
]
}
}
}
}
]
The device information is shown under the factorProfile (profile.name) which is documented here but doesn't show an example of push.

How to get rid of "API must not have local definitions (i.e. only $refs are allowed)" Swaggerhub standardization error with Springfox

I have swagger api-docs.json definition generated by SpringFox.
Below minimal-reproducible-example:
{
"swagger": "2.0",
"info": {
"description": "Example REST API.",
"version": "15.11.02",
"title": "Example REST API",
"contact": {
"name": "ExampleTeam",
"url": "https://example.com/",
"email": "support#example.com"
},
"license": {
"name": "Apache License 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
},
"host": "d01088db.ngrok.io",
"basePath": "/cloud",
"tags": [
{
"name": "All Endpoints",
"description": " "
}
],
"paths": {
"/api/v2/users/{userId}/jobs/{jobId}": {
"get": {
"tags": [
"Builds",
"All Endpoints"
],
"summary": "Get job.",
"operationId": "getJobUsingGET",
"produces": [
"*/*"
],
"parameters": [
{
"name": "jobId",
"in": "path",
"description": "jobId",
"required": true,
"type": "integer",
"format": "int64"
},
{
"name": "userId",
"in": "path",
"description": "userId",
"required": true,
"type": "integer",
"format": "int64"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/APIPipelineJob"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
},
"deprecated": false
}
}
},
"definitions": {
"APIPipelineJob": {
"type": "object",
"properties": {
"archiveTime": {
"type": "string",
"format": "date-time",
"example": "example"
},
"content": {
"type": "string",
"example": "example"
},
"createTime": {
"type": "string",
"format": "date-time",
"example": "example"
},
"id": {
"type": "integer",
"format": "int64",
"example": "example"
},
"name": {
"type": "string",
"example": "example"
},
"selfURI": {
"type": "string",
"example": "example"
},
"type": {
"type": "string",
"example": "example",
"enum": [
"BUILD",
"DEPLOY"
]
},
"userId": {
"type": "integer",
"format": "int64",
"example": "example"
}
},
"title": "APIPipelineJob",
"xml": {
"name": "APIPipelineJob",
"attribute": false,
"wrapped": false
}
}
}
}
When I import it to SwaggerHub I got standardization error:
'definitions.*' not allowed -> API must not have local definitions (i.e. only $refs are allowed)
I have found the recommended solution in SwaggerHub documentation
But here is my question how to achieve:
split into domains(then using a reference), or
inline schemas
with Springfox
Or maybe there is another way to get rid of the above standardization error?
If you go to your home page, then hover over your organization on the left hand side and go to settings > Standardization, you should see some options. Unselect "API must not have local definitions (i.e. only $refs are allowed)" at the bottom.
And don't forget to save at the top right!

Resources